[FIX] printer_zpl2: Adapt code about having the library embedded

This commit is contained in:
Pedro M. Baeza
2022-09-09 11:10:59 +02:00
parent f40c0e4d29
commit 68ab41ca6f
7 changed files with 9 additions and 40 deletions

View File

@@ -10,7 +10,6 @@
"Apertoso NV, Odoo Community Association (OCA)", "Apertoso NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/report-print-send", "website": "https://github.com/OCA/report-print-send",
"license": "AGPL-3", "license": "AGPL-3",
"external_dependencies": {"python": ["zpl2"]},
"depends": ["base_report_to_printer"], "depends": ["base_report_to_printer"],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",

View File

@@ -14,12 +14,9 @@ from odoo import _, api, exceptions, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tools.safe_eval import safe_eval, wrap_module from odoo.tools.safe_eval import safe_eval, wrap_module
_logger = logging.getLogger(__name__) from . import zpl2
try: _logger = logging.getLogger(__name__)
import zpl2
except ImportError:
_logger.debug("Cannot `import zpl2`.")
class PrintingLabelZpl2(models.Model): class PrintingLabelZpl2(models.Model):

View File

@@ -5,12 +5,10 @@ import logging
from odoo import api, fields, models from odoo import api, fields, models
from . import zpl2
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try:
import zpl2
except ImportError:
_logger.debug("Cannot `import zpl2`.")
DEFAULT_PYTHON_CODE = """# Python One-Liners DEFAULT_PYTHON_CODE = """# Python One-Liners
# - object: %s record on which the action is triggered; may be void # - object: %s record on which the action is triggered; may be void

View File

@@ -8,15 +8,7 @@
import binascii import binascii
import math import math
try:
from PIL import ImageOps from PIL import ImageOps
except:
ImageOps = None
try:
strcast = unicode
except:
strcast = str
# Constants for the printer configuration management # Constants for the printer configuration management
CONF_RELOAD_FACTORY = "F" CONF_RELOAD_FACTORY = "F"
@@ -136,7 +128,7 @@ class Zpl2(object):
def _write_command(self, data): def _write_command(self, data):
"""Adds a complete command to buffer""" """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): def _generate_arguments(self, arguments, kwargs):
"""Generate a zebra arguments from an argument names list and a dict of """Generate a zebra arguments from an argument names list and a dict of
@@ -492,12 +484,6 @@ class Zpl2(object):
def graphic_field(self, right, down, pil_image): def graphic_field(self, right, down, pil_image):
"""Encode a PIL image into an ASCII string suitable for ZPL printers""" """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 width, height = pil_image.size
rounded_width = int(math.ceil(width / 8.0) * 8) rounded_width = int(math.ceil(width / 8.0) * 8)
# Transform the image : # Transform the image :

View File

@@ -1,19 +1,12 @@
# Copyright 2016 LasLabs Inc. # Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
import mock import mock
from odoo import exceptions from odoo import exceptions
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
_logger = logging.getLogger(__name__) from ..models import zpl2
try:
import zpl2
except ImportError:
_logger.debug("Cannot `import zpl2`.")
model = "odoo.addons.base_report_to_printer.models.printing_server" model = "odoo.addons.base_report_to_printer.models.printing_server"

View File

@@ -11,12 +11,9 @@ from PIL import Image, ImageOps
from odoo import _, fields, models from odoo import _, fields, models
_logger = logging.getLogger(__name__) from ..models import zpl2
try: _logger = logging.getLogger(__name__)
import zpl2
except ImportError:
_logger.debug("Cannot `import zpl2`.")
def _compute_arg(data, arg): def _compute_arg(data, arg):

View File

@@ -1,3 +1,2 @@
# generated from manifests external_dependencies # generated from manifests external_dependencies
pycups pycups
zpl2