mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] Add missing tests for graphics ZPL2 feature
This commit is contained in:
committed by
Lois Rilo
parent
2b02938cd8
commit
15d8bf5100
@@ -121,8 +121,9 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
zpl2.ARG_ROUNDING: component.rounding,
|
zpl2.ARG_ROUNDING: component.rounding,
|
||||||
})
|
})
|
||||||
elif component.component_type == 'graphic':
|
elif component.component_type == 'graphic':
|
||||||
|
image = component.graphic_image or data
|
||||||
pil_image = Image.open(io.BytesIO(
|
pil_image = Image.open(io.BytesIO(
|
||||||
base64.b64decode(component.graphic_image or data)))
|
base64.b64decode(image)))
|
||||||
if component.width and component.height:
|
if component.width and component.height:
|
||||||
pil_image = pil_image.resize(
|
pil_image = pil_image.resize(
|
||||||
(component.width, component.height))
|
(component.width, component.height))
|
||||||
|
|||||||
@@ -3,10 +3,17 @@
|
|||||||
# 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 mock
|
import mock
|
||||||
|
import logging
|
||||||
|
|
||||||
from odoo import exceptions
|
from odoo import exceptions
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
@@ -974,3 +981,91 @@ class TestPrintingLabelZpl2(TransactionCase):
|
|||||||
'^JUR\n'
|
'^JUR\n'
|
||||||
# Label end
|
# Label end
|
||||||
'^XZ'.format(contents=data))
|
'^XZ'.format(contents=data))
|
||||||
|
|
||||||
|
def test_graphic_label_contents_blank(self):
|
||||||
|
""" Check contents of a image label """
|
||||||
|
label = self.new_label()
|
||||||
|
data = 'R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='
|
||||||
|
self.new_component({
|
||||||
|
'label_id': label.id,
|
||||||
|
'component_type': 'graphic',
|
||||||
|
'data': '"' + data + '"',
|
||||||
|
})
|
||||||
|
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
|
||||||
|
self.assertEqual(
|
||||||
|
contents,
|
||||||
|
"^XA\n"
|
||||||
|
"^PW480\n"
|
||||||
|
"^CI28\n"
|
||||||
|
"^LH10,10\n"
|
||||||
|
"^FO10,10^GFA,1.0,1.0,1.0,b'00'^FS\n"
|
||||||
|
"^JUR\n"
|
||||||
|
"^XZ")
|
||||||
|
|
||||||
|
def test_graphic_label_contents_blank_rotated(self):
|
||||||
|
""" Check contents of image rotated label """
|
||||||
|
label = self.new_label()
|
||||||
|
data = 'R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='
|
||||||
|
self.new_component({
|
||||||
|
'label_id': label.id,
|
||||||
|
'component_type': 'graphic',
|
||||||
|
'data': '"' + data + '"',
|
||||||
|
'height': 10,
|
||||||
|
'width': 10,
|
||||||
|
'reverse_print': 1,
|
||||||
|
'orientation': zpl2.ORIENTATION_ROTATED,
|
||||||
|
})
|
||||||
|
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
|
||||||
|
self.assertEqual(
|
||||||
|
contents,
|
||||||
|
"^XA\n"
|
||||||
|
"^PW480\n"
|
||||||
|
"^CI28\n"
|
||||||
|
"^LH10,10\n"
|
||||||
|
"^FO10,10^GFA,20.0,20.0,2.0,"
|
||||||
|
"b'FFC0FFC0FFC0FFC0FFC0FFC0FFC0FFC0FFC0FFC0'^FS\n"
|
||||||
|
"^JUR\n"
|
||||||
|
"^XZ")
|
||||||
|
|
||||||
|
def test_graphic_label_contents_blank_inverted(self):
|
||||||
|
""" Check contents of a image inverted label """
|
||||||
|
label = self.new_label()
|
||||||
|
data = 'R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='
|
||||||
|
self.new_component({
|
||||||
|
'label_id': label.id,
|
||||||
|
'component_type': 'graphic',
|
||||||
|
'data': '"' + data + '"',
|
||||||
|
'orientation': zpl2.ORIENTATION_INVERTED,
|
||||||
|
})
|
||||||
|
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
|
||||||
|
self.assertEqual(
|
||||||
|
contents,
|
||||||
|
"^XA\n"
|
||||||
|
"^PW480\n"
|
||||||
|
"^CI28\n"
|
||||||
|
"^LH10,10\n"
|
||||||
|
"^FO10,10^GFA,1.0,1.0,1.0,b'00'^FS\n"
|
||||||
|
"^JUR\n"
|
||||||
|
"^XZ")
|
||||||
|
|
||||||
|
def test_graphic_label_contents_blank_bottom(self):
|
||||||
|
""" Check contents of a image bottom label """
|
||||||
|
label = self.new_label()
|
||||||
|
data = 'R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='
|
||||||
|
self.new_component({
|
||||||
|
'label_id': label.id,
|
||||||
|
'component_type': 'graphic',
|
||||||
|
'data': '"' + data + '"',
|
||||||
|
'orientation': zpl2.ORIENTATION_BOTTOM_UP,
|
||||||
|
})
|
||||||
|
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
|
||||||
|
self.assertEqual(
|
||||||
|
contents,
|
||||||
|
"^XA\n"
|
||||||
|
"^PW480\n"
|
||||||
|
"^CI28\n"
|
||||||
|
"^LH10,10\n"
|
||||||
|
"^FO10,10^GFA,1.0,1.0,1.0,b'00'^FS\n"
|
||||||
|
"^JUR\n"
|
||||||
|
"^XZ")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user