diff --git a/product_print_zpl_barcode/__manifest__.py b/product_print_zpl_barcode/__manifest__.py index 4fda81c..23bcabb 100644 --- a/product_print_zpl_barcode/__manifest__.py +++ b/product_print_zpl_barcode/__manifest__.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-2018 Akretion +# Copyright 2016-2020 Akretion (http://www.akretion.com/) # @author: Alexis de Lattre # 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 . """, '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', ], diff --git a/product_print_zpl_barcode/security/ir.model.access.csv b/product_print_zpl_barcode/security/ir.model.access.csv new file mode 100644 index 0000000..0c00ff6 --- /dev/null +++ b/product_print_zpl_barcode/security/ir.model.access.csv @@ -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 diff --git a/product_print_zpl_barcode/views/product.xml b/product_print_zpl_barcode/views/product.xml index 0b244ce..3153508 100644 --- a/product_print_zpl_barcode/views/product.xml +++ b/product_print_zpl_barcode/views/product.xml @@ -14,7 +14,7 @@
-
diff --git a/product_print_zpl_barcode/wizard/__init__.py b/product_print_zpl_barcode/wizard/__init__.py index 7106895..71c6c20 100644 --- a/product_print_zpl_barcode/wizard/__init__.py +++ b/product_print_zpl_barcode/wizard/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import product_print_zpl_barcode diff --git a/product_print_zpl_barcode/wizard/product_print_zpl_barcode.py b/product_print_zpl_barcode/wizard/product_print_zpl_barcode.py index 866aa53..7f879ce 100644 --- a/product_print_zpl_barcode/wizard/product_print_zpl_barcode.py +++ b/product_print_zpl_barcode/wizard/product_print_zpl_barcode.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- -# © 2016 Akretion (Alexis de Lattre ) +# Copyright 2016-2020 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # 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): - 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 match.get('match'): - match_rule = rule.id - break - self.rule_id = match_rule + for wiz in self: + match_rule = False + 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 + 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, diff --git a/product_print_zpl_barcode/wizard/product_print_zpl_barcode_view.xml b/product_print_zpl_barcode/wizard/product_print_zpl_barcode_view.xml index e5db3a6..3f481ec 100644 --- a/product_print_zpl_barcode/wizard/product_print_zpl_barcode_view.xml +++ b/product_print_zpl_barcode/wizard/product_print_zpl_barcode_view.xml @@ -1,6 +1,6 @@ @@ -33,17 +33,17 @@ - +