MIG product_print_zpl_barcode from v10 to v14
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016-2018 Akretion
|
||||
# Copyright 2016-2020 Akretion (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Product Generate Price Weight Barcode',
|
||||
'version': '10.0.1.0.0',
|
||||
'version': '14.0.1.0.0',
|
||||
'category': 'Extra Tools',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Add a wizard to print product barcode stickers on ZPL printer',
|
||||
@@ -27,21 +26,21 @@ This module adds a wizard on product.product form view which allows to generate
|
||||
* price per kg
|
||||
* EAN13 barcode
|
||||
|
||||
Roadmap: It would be cool one to day use the OCA module *printer_zpl2* or the underlying *zpl2* lib.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion
|
||||
<alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
# We depend on point_of_sale and not only 'product'
|
||||
# because the weight barcode rules are added by the point_of_sale module
|
||||
# because the price barcode rule is added by the point_of_sale module
|
||||
# (the weight barcode rule is added by the stock module)
|
||||
'depends': [
|
||||
'point_of_sale',
|
||||
'barcodes',
|
||||
'base_report_to_printer',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/product_print_zpl_barcode_view.xml',
|
||||
'views/product.xml',
|
||||
],
|
||||
|
||||
2
product_print_zpl_barcode/security/ir.model.access.csv
Normal file
2
product_print_zpl_barcode/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_product_print_zpl_barcode,Full access to product.print.zpl.barcode wizard,model_product_print_zpl_barcode,base_report_to_printer.printing_group_user,1,1,1,1
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<field name="inherit_id" ref="product.product_normal_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(product_print_zpl_barcode.product_print_zpl_barcode_action)d" type="action" string="Print Barcode"/>
|
||||
<button name="%(product_print_zpl_barcode.product_print_zpl_barcode_action)d" type="action" string="Print Barcode" groups="base_report_to_printer.printing_group_user"/>
|
||||
</header>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import product_print_zpl_barcode
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# Copyright 2016-2020 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_compare, float_is_zero
|
||||
import odoo.addons.decimal_precision as dp
|
||||
import base64
|
||||
import re
|
||||
|
||||
@@ -16,7 +15,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(ProductPrintZplBarcode, self).default_get(fields_list)
|
||||
res = super().default_get(fields_list)
|
||||
assert self._context.get('active_model') == 'product.product',\
|
||||
'wrong active_model, should be product.product'
|
||||
product_id = self._context.get('active_id')
|
||||
@@ -27,7 +26,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
raise UserError(_(
|
||||
"Product '%s' doesn't have a barcode") % product.display_name)
|
||||
nomenclature = self.env.ref('barcodes.default_barcode_nomenclature')
|
||||
company = self.env.user.company_id
|
||||
company = self.env.company
|
||||
posconfig = self.env['pos.config'].sudo().search(
|
||||
[('company_id', '=', company.id)], limit=1)
|
||||
if posconfig:
|
||||
@@ -74,7 +73,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
currency_id = fields.Many2one(
|
||||
related='pricelist_id.currency_id', readonly=True)
|
||||
# TODO: for the moment, we only support weight, but...
|
||||
quantity = fields.Float(digits=dp.get_precision('Stock Weight'))
|
||||
quantity = fields.Float(digits='Stock Weight')
|
||||
price_uom = fields.Monetary(
|
||||
readonly=True, string="Price per Unit of Measure",
|
||||
compute='_compute_price') # given by pricelist
|
||||
@@ -102,18 +101,18 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
wiz.price_uom = price_uom
|
||||
wiz.price = price_uom * wiz.quantity
|
||||
|
||||
@api.one
|
||||
@api.depends('nomenclature_id')
|
||||
def _compute_rule_id(self):
|
||||
for wiz in self:
|
||||
match_rule = False
|
||||
if self.nomenclature_id and self.barcode:
|
||||
for rule in self.nomenclature_id.rule_ids:
|
||||
match = self.nomenclature_id.match_pattern(
|
||||
self.barcode, rule.pattern)
|
||||
if wiz.nomenclature_id and wiz.barcode:
|
||||
for rule in wiz.nomenclature_id.rule_ids:
|
||||
match = wiz.nomenclature_id.match_pattern(
|
||||
wiz.barcode, rule.pattern)
|
||||
if match.get('match'):
|
||||
match_rule = rule.id
|
||||
break
|
||||
self.rule_id = match_rule
|
||||
wiz.rule_id = match_rule
|
||||
|
||||
def _prepare_price_weight_barcode_type(self):
|
||||
dpo = self.env['decimal.precision']
|
||||
@@ -154,11 +153,11 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
"The value to encode in the barcode (%s) is superior "
|
||||
"to the maximum value allowed by the barcode pattern (%s).")
|
||||
% (value, max_value))
|
||||
value_u = unicode(value)
|
||||
value_u_split = value_u.split('.')
|
||||
assert len(value_u_split) == 2
|
||||
value_n = value_u_split[0]
|
||||
value_d = value_u_split[1]
|
||||
value_str = str(value)
|
||||
value_str_split = value_str.split('.')
|
||||
assert len(value_str_split) == 2
|
||||
value_n = value_str_split[0]
|
||||
value_d = value_str_split[1]
|
||||
assert len(value_n) <= pattern_val.count('N')
|
||||
barcode += value_n.zfill(pattern_val.count('N'))
|
||||
# end fill doesn't exists... so:
|
||||
@@ -181,9 +180,9 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
'quantity': value,
|
||||
'uom_name': self.uom_id.name,
|
||||
}
|
||||
zpl_encoded = zpl_unicode.encode('utf-8')
|
||||
zpl_bytes = zpl_unicode.encode('utf-8')
|
||||
vals = {
|
||||
'zpl_file': zpl_encoded.encode('base64'),
|
||||
'zpl_file': base64.encodebytes(zpl_bytes),
|
||||
'barcode': barcode,
|
||||
}
|
||||
return vals
|
||||
@@ -234,9 +233,9 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
'currency_symbol': self.currency_id.symbol, # symbol is a required field
|
||||
'copies': self.copies,
|
||||
}
|
||||
zpl_encoded = zpl_unicode.encode('utf-8')
|
||||
zpl_bytes = zpl_unicode.encode('utf-8')
|
||||
vals = {
|
||||
'zpl_file': zpl_encoded.encode('base64'),
|
||||
'zpl_file': base64.encodebytes(zpl_bytes),
|
||||
'barcode': self.barcode, # unchanged
|
||||
}
|
||||
return vals
|
||||
@@ -264,9 +263,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
|
||||
})
|
||||
self.write(vals)
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'product_print_zpl_barcode',
|
||||
'product_print_zpl_barcode_action')
|
||||
action = self.env.ref('product_print_zpl_barcode.product_print_zpl_barcode_action').read()[0]
|
||||
action.update({
|
||||
'res_id': self.id,
|
||||
'context': self._context,
|
||||
@@ -278,12 +275,10 @@ class ProductPrintZplBarcode(models.TransientModel):
|
||||
raise UserError(_(
|
||||
"You must select a ZPL Printer."))
|
||||
self.zpl_printer_id.print_document(
|
||||
self.zpl_filename, base64.decodestring(self.zpl_file), 'raw')
|
||||
self.zpl_filename, base64.decodestring(self.zpl_file), format='raw')
|
||||
action = True
|
||||
if self._context.get('print_and_new'):
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'product_print_zpl_barcode',
|
||||
'product_print_zpl_barcode_action')
|
||||
action = self.env.ref('product_print_zpl_barcode.product_print_zpl_barcode_action').read()[0]
|
||||
action.update({
|
||||
'views': False,
|
||||
'context': self._context,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2016 Akretion (http://www.akretion.com/)
|
||||
Copyright 2016-2020 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
@@ -33,17 +33,17 @@
|
||||
</div>
|
||||
</group>
|
||||
<group name="step2" states="step2" string="Label">
|
||||
<field name="price"/>
|
||||
<field name="price" attrs="{'invisible': [('barcode_type', 'not in', ('price', 'weight'))]}"/>
|
||||
<field name="zpl_file" filename="zpl_filename" />
|
||||
<field name="zpl_filename" invisible="1"/>
|
||||
<field name="zpl_printer_id" required="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link" states="step1"/>
|
||||
<button special="cancel" string="Cancel" class="btn-default" states="step1"/>
|
||||
<button name="print_zpl" type="object" string="Print" class="btn-primary" states="step2"/>
|
||||
<button name="print_zpl" type="object" string="Print and New" class="btn-primary" context="{'print_and_new': True}" attrs="{'invisible': ['|', ('state', '!=', 'step2'), ('barcode_type', '=', 'product')]}"/>
|
||||
<button special="cancel" string="Close" class="oe_link" states="step2"/>
|
||||
<button special="cancel" string="Close" class="btn-default" states="step2"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user