From 68ab41ca6f248a5f16801b5645f26023851788d2 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 9 Sep 2022 11:10:59 +0200 Subject: [PATCH] [FIX] printer_zpl2: Adapt code about having the library embedded --- printer_zpl2/__manifest__.py | 1 - printer_zpl2/models/printing_label_zpl2.py | 7 ++----- .../models/printing_label_zpl2_component.py | 6 ++---- printer_zpl2/models/zpl2.py | 18 ++---------------- printer_zpl2/tests/test_printing_label_zpl2.py | 9 +-------- printer_zpl2/wizard/wizard_import_zpl2.py | 7 ++----- requirements.txt | 1 - 7 files changed, 9 insertions(+), 40 deletions(-) diff --git a/printer_zpl2/__manifest__.py b/printer_zpl2/__manifest__.py index 7d3d916145d..4ed0f44db44 100644 --- a/printer_zpl2/__manifest__.py +++ b/printer_zpl2/__manifest__.py @@ -10,7 +10,6 @@ "Apertoso NV, Odoo Community Association (OCA)", "website": "https://github.com/OCA/report-print-send", "license": "AGPL-3", - "external_dependencies": {"python": ["zpl2"]}, "depends": ["base_report_to_printer"], "data": [ "security/ir.model.access.csv", diff --git a/printer_zpl2/models/printing_label_zpl2.py b/printer_zpl2/models/printing_label_zpl2.py index dfd860a149d..e9e5e9b0908 100644 --- a/printer_zpl2/models/printing_label_zpl2.py +++ b/printer_zpl2/models/printing_label_zpl2.py @@ -14,12 +14,9 @@ from odoo.exceptions import ValidationError from odoo.tools.safe_eval import safe_eval, wrap_module -_logger = logging.getLogger(__name__) +from . import zpl2 -try: - import zpl2 -except ImportError: - _logger.debug("Cannot `import zpl2`.") +_logger = logging.getLogger(__name__) class PrintingLabelZpl2(models.Model): diff --git a/printer_zpl2/models/printing_label_zpl2_component.py b/printer_zpl2/models/printing_label_zpl2_component.py index 9342ec54775..eccd2ef6a66 100644 --- a/printer_zpl2/models/printing_label_zpl2_component.py +++ b/printer_zpl2/models/printing_label_zpl2_component.py @@ -5,12 +5,10 @@ from odoo import api, fields, models +from . import zpl2 + _logger = logging.getLogger(__name__) -try: - import zpl2 -except ImportError: - _logger.debug("Cannot `import zpl2`.") DEFAULT_PYTHON_CODE = """# Python One-Liners # - object: %s record on which the action is triggered; may be void diff --git a/printer_zpl2/models/zpl2.py b/printer_zpl2/models/zpl2.py index 00db219238b..d9600b62339 100644 --- a/printer_zpl2/models/zpl2.py +++ b/printer_zpl2/models/zpl2.py @@ -8,15 +8,7 @@ import binascii import math -try: - from PIL import ImageOps -except: - ImageOps = None - -try: - strcast = unicode -except: - strcast = str +from PIL import ImageOps # Constants for the printer configuration management CONF_RELOAD_FACTORY = "F" @@ -136,7 +128,7 @@ def _enforce(self, value, minimum=1, maximum=32000): def _write_command(self, data): """Adds a complete command to buffer""" - self._buffer.append(strcast(data).encode(self.encoding)) + self._buffer.append(str(data).encode(self.encoding)) def _generate_arguments(self, arguments, kwargs): """Generate a zebra arguments from an argument names list and a dict of @@ -492,12 +484,6 @@ def graphic_circle(self, right, down, graphic_format): def graphic_field(self, right, down, pil_image): """Encode a PIL image into an ASCII string suitable for ZPL printers""" - if ImageOps is None: - # Importing ImageOps from PIL didn't work - raise Exception( - "You must install Pillow to be able to use the graphic" - " fields feature" - ) width, height = pil_image.size rounded_width = int(math.ceil(width / 8.0) * 8) # Transform the image : diff --git a/printer_zpl2/tests/test_printing_label_zpl2.py b/printer_zpl2/tests/test_printing_label_zpl2.py index f78322d9129..41f1470f8b0 100644 --- a/printer_zpl2/tests/test_printing_label_zpl2.py +++ b/printer_zpl2/tests/test_printing_label_zpl2.py @@ -1,19 +1,12 @@ # Copyright 2016 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import logging - import mock from odoo import exceptions from odoo.tests.common import TransactionCase -_logger = logging.getLogger(__name__) - -try: - import zpl2 -except ImportError: - _logger.debug("Cannot `import zpl2`.") +from ..models import zpl2 model = "odoo.addons.base_report_to_printer.models.printing_server" diff --git a/printer_zpl2/wizard/wizard_import_zpl2.py b/printer_zpl2/wizard/wizard_import_zpl2.py index 6493564debd..f6adc7936df 100644 --- a/printer_zpl2/wizard/wizard_import_zpl2.py +++ b/printer_zpl2/wizard/wizard_import_zpl2.py @@ -11,12 +11,9 @@ from odoo import _, fields, models -_logger = logging.getLogger(__name__) +from ..models import zpl2 -try: - import zpl2 -except ImportError: - _logger.debug("Cannot `import zpl2`.") +_logger = logging.getLogger(__name__) def _compute_arg(data, arg): diff --git a/requirements.txt b/requirements.txt index f1fc07a2902..342693141bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ # generated from manifests external_dependencies pycups -zpl2