Skip to content

Commit

Permalink
[FIX] printer_zpl2: Adapt code about having the library embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Oct 2, 2022
1 parent f40c0e4 commit 68ab41c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 40 deletions.
1 change: 0 additions & 1 deletion printer_zpl2/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions printer_zpl2/models/printing_label_zpl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions printer_zpl2/models/printing_label_zpl2_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions printer_zpl2/models/zpl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down
9 changes: 1 addition & 8 deletions printer_zpl2/tests/test_printing_label_zpl2.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
7 changes: 2 additions & 5 deletions printer_zpl2/wizard/wizard_import_zpl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# generated from manifests external_dependencies
pycups
zpl2

0 comments on commit 68ab41c

Please sign in to comment.