diff --git a/printer_zpl2/README.rst b/printer_zpl2/README.rst index 5400be5..14f032f 100644 --- a/printer_zpl2/README.rst +++ b/printer_zpl2/README.rst @@ -28,9 +28,7 @@ To configure this module, you need to: #. Use the Test Mode tab during the creation It's also possible to add a label printing wizard on any model by creating a new *ir.actions.act_window* record. -For example, to add the printing wizard on the *product.product* model : - -.. code-block:: xml +For example, to add the printing wizard on the *product.product* model :: ) +# Copyright (C) 2016 SUBTENO-IT () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/printer_zpl2/__manifest__.py b/printer_zpl2/__manifest__.py index 44e7b51..11ed314 100644 --- a/printer_zpl2/__manifest__.py +++ b/printer_zpl2/__manifest__.py @@ -1,11 +1,12 @@ -# Copyright (C) 2016 SYLEAM () +# Copyright (C) 2016 SUBTENO-IT () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Printer ZPL II', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Printer', - 'author': 'SYLEAM, Apertoso NV, Odoo Community Association (OCA)', + 'author': 'SUBTENO-IT, FLorent de Labarre, ' + 'Apertoso NV, Odoo Community Association (OCA)', 'website': 'http://www.syleam.fr/', 'license': 'AGPL-3', 'external_dependencies': { diff --git a/printer_zpl2/models/printing_label_zpl2.py b/printer_zpl2/models/printing_label_zpl2.py index e6b9609..273c482 100644 --- a/printer_zpl2/models/printing_label_zpl2.py +++ b/printer_zpl2/models/printing_label_zpl2.py @@ -42,7 +42,7 @@ class PrintingLabelZpl2(models.Model): component_ids = fields.One2many( comodel_name='printing.label.zpl2.component', inverse_name='label_id', string='Label Components', - help='Components which will be printed on the label.') + help='Components which will be printed on the label.', copy=True) restore_saved_config = fields.Boolean( string="Restore printer's configuration", help="Restore printer's saved configuration and end of each label ", @@ -85,6 +85,9 @@ class PrintingLabelZpl2(models.Model): }) data = safe_eval(component.data, eval_args) or '' + if data == 'component_not_show': + continue + # Generate a list of elements if the component is repeatable for idx in range( component.repeat_offset, @@ -151,9 +154,14 @@ class PrintingLabelZpl2(models.Model): component.diagonal_orientation, }) elif component.component_type == 'graphic': - image = component.graphic_image or data - pil_image = Image.open(io.BytesIO( - base64.b64decode(image))).convert('RGB') + # During the on_change don't take the bin_size + image = component.with_context(bin_size_graphic_image=False)\ + .graphic_image or data + try: + pil_image = Image.open(io.BytesIO( + base64.b64decode(image))).convert('RGB') + except Exception: + continue if component.width and component.height: pil_image = pil_image.resize( (component.width, component.height)) @@ -292,7 +300,7 @@ class PrintingLabelZpl2(models.Model): record = Obj.search([('id', '=', self.record_id)], limit=1) if not record: record = Obj.search([], limit=1, order='id desc') - self.record_id = record.id + self.record_id = record.id return record diff --git a/printer_zpl2/models/printing_label_zpl2_component.py b/printer_zpl2/models/printing_label_zpl2_component.py index efdd593..c2fde3b 100644 --- a/printer_zpl2/models/printing_label_zpl2_component.py +++ b/printer_zpl2/models/printing_label_zpl2_component.py @@ -16,8 +16,10 @@ DEFAULT_PYTHON_CODE = """# Python One-Liners # - page_number: Current Page # - page_count: Total Page # - time, datetime: Python libraries +# - return 'component_not_show' to don't show this component # Exemple : object.name + "" """ diff --git a/printer_zpl2/tests/test_generate_action.py b/printer_zpl2/tests/test_generate_action.py index b9e8450..0669bd2 100644 --- a/printer_zpl2/tests/test_generate_action.py +++ b/printer_zpl2/tests/test_generate_action.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 Florent Mirieu () +# Copyright (C) 2018 Florent de Labarre () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase diff --git a/printer_zpl2/tests/test_printing_label_zpl2.py b/printer_zpl2/tests/test_printing_label_zpl2.py index 084b19b..f330cd2 100644 --- a/printer_zpl2/tests/test_printing_label_zpl2.py +++ b/printer_zpl2/tests/test_printing_label_zpl2.py @@ -1116,3 +1116,22 @@ class TestPrintingLabelZpl2(TransactionCase): '^FO50,50^GB100,100,100^FS\n' '^JUR\n' '^XZ') + + def test_zpl2_component_not_show(self): + """ Check to don't show no things """ + label = self.new_label() + data = 'component_not_show' + self.new_component({ + 'label_id': label.id, + 'component_type': 'zpl2_raw', + 'data': '"' + data + '"', + }) + contents = label._generate_zpl2_data(self.printer).decode("utf-8") + self.assertEqual( + contents, + '^XA\n' + '^PW480\n' + '^CI28\n' + '^LH10,10\n' + '^JUR\n' + '^XZ') diff --git a/printer_zpl2/tests/test_test_mode.py b/printer_zpl2/tests/test_test_mode.py index 8917142..7fada83 100644 --- a/printer_zpl2/tests/test_test_mode.py +++ b/printer_zpl2/tests/test_test_mode.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 Florent Mirieu () +# Copyright (C) 2018 Florent de Labarre () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import mock diff --git a/printer_zpl2/tests/test_wizard_import_zpl2.py b/printer_zpl2/tests/test_wizard_import_zpl2.py index 3360b53..cbe1673 100644 --- a/printer_zpl2/tests/test_wizard_import_zpl2.py +++ b/printer_zpl2/tests/test_wizard_import_zpl2.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 Florent Mirieu () +# Copyright (C) 2018 Florent de Labarre () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase diff --git a/printer_zpl2/views/printing_label_zpl2.xml b/printer_zpl2/views/printing_label_zpl2.xml index 8cf96bb..69008ba 100644 --- a/printer_zpl2/views/printing_label_zpl2.xml +++ b/printer_zpl2/views/printing_label_zpl2.xml @@ -1,6 +1,6 @@ diff --git a/printer_zpl2/wizard/wizard_import_zpl2.py b/printer_zpl2/wizard/wizard_import_zpl2.py index 3e89d10..451affa 100644 --- a/printer_zpl2/wizard/wizard_import_zpl2.py +++ b/printer_zpl2/wizard/wizard_import_zpl2.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 Florent Mirieu () +# Copyright (C) 2018 Florent de Labarre () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -376,13 +376,12 @@ class WizardImportZPl2(models.TransientModel): return 0 def import_zpl2(self): + self.ensure_one() Zpl2Component = self.env['printing.label.zpl2.component'] if self.delete_component: self.mapped('label_id.component_ids').unlink() - Model = self.env['printing.label.zpl2.component'] - self.model_fields = Model.fields_get() sequence = self._start_sequence() default = {} @@ -423,10 +422,12 @@ class WizardImportZPl2(models.TransientModel): vals['orientation'] = 'N' # Field + Zpl2Component = self.env['printing.label.zpl2.component'] + model_fields = Zpl2Component.fields_get() component = {} for field, value in vals.items(): - if field in self.model_fields.keys(): - field_type = self.model_fields[field].get('type', False) + if field in model_fields.keys(): + field_type = model_fields[field].get('type', False) if field_type == 'boolean': if not value or value == zpl2.BOOL_NO: value = False