Merge PR #205 into 12.0

Signed-off-by dreispt
This commit is contained in:
OCA-git-bot
2021-11-29 08:45:08 +00:00
5 changed files with 56 additions and 22 deletions

View File

@@ -55,7 +55,8 @@ class PrintingLabelZpl2(models.Model):
extra = fields.Text(string="Extra", default='{}')
printer_id = fields.Many2one(
comodel_name='printing.printer', string='Printer')
labelary_image = fields.Binary(string='Image from Labelary', readonly=True)
labelary_image = fields.Binary(string='Image from Labelary',
compute='_compute_labelary_image')
labelary_dpmm = fields.Selection(
selection=[
('6dpmm', '6dpmm (152 pdi)'),
@@ -312,15 +313,19 @@ class PrintingLabelZpl2(models.Model):
if record:
label.print_label(label.printer_id, record, **extra)
@api.onchange(
@api.depends(
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
'component_ids', 'origin_x', 'origin_y')
def _on_change_labelary(self):
'component_ids', 'origin_x', 'origin_y', 'test_labelary_mode')
def _compute_labelary_image(self):
for label in self:
label.labelary_image = label._generate_labelary_image()
def _generate_labelary_image(self):
self.ensure_one()
if not(self.test_labelary_mode and self.record_id and
self.labelary_width and self.labelary_height and
self.labelary_dpmm and self.component_ids):
return
return False
record = self._get_record()
if record:
# If case there an error (in the data field with the safe_eval
@@ -349,17 +354,11 @@ class PrintingLabelZpl2(models.Model):
new_im.paste(im, (1, 1))
imgByteArr = io.BytesIO()
new_im.save(imgByteArr, format='PNG')
self.labelary_image = base64.b64encode(
imgByteArr.getvalue())
return base64.b64encode(imgByteArr.getvalue())
else:
return {'warning': {
'title': _('Error with Labelary API.'),
'message': response.status_code,
}}
_logger.warning(
_("Error with Labelary API. %s") % response.status_code)
except Exception as e:
self.labelary_image = False
return {'warning': {
'title': _('Some thing is wrong.'),
'message': e,
}}
_logger.warning(_("Error with Labelary API. %s") % e)
return False

View File

@@ -184,3 +184,19 @@ class PrintingLabelZpl2Component(models.Model):
string='Image', attachment=True,
help='This field holds a static image to print. '
'If not set, the data field is evaluated.')
def action_plus_origin_x(self):
self.ensure_one()
self.origin_x += 10
def action_minus_origin_x(self):
self.ensure_one()
self.origin_x -= 10
def action_plus_origin_y(self):
self.ensure_one()
self.origin_y += 10
def action_minus_origin_y(self):
self.ensure_one()
self.origin_y -= 10

View File

@@ -1135,3 +1135,22 @@ class TestPrintingLabelZpl2(TransactionCase):
'^LH10,10\n'
'^JUR\n'
'^XZ')
def test_zpl2_component_quick_move(self):
""" Check component quick move """
label = self.new_label()
component = self.new_component({
'label_id': label.id,
'component_type': 'zpl2_raw',
'data': '""',
'origin_x': 20,
'origin_y': 30,
})
component.action_plus_origin_x()
self.assertEqual(30, component.origin_x)
component.action_minus_origin_x()
self.assertEqual(20, component.origin_x)
component.action_plus_origin_y()
self.assertEqual(40, component.origin_y)
component.action_minus_origin_y()
self.assertEqual(30, component.origin_y)

View File

@@ -52,8 +52,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
def test_emulation_without_params(self):
""" Check if not execute next if not in this mode """
self.label.test_labelary_mode = False
self.label._on_change_labelary()
self.assertIs(self.label.labelary_image, None)
self.assertIs(self.label.labelary_image, False)
def test_emulation_with_bad_header(self):
""" Check if bad header """
@@ -65,7 +64,6 @@ class TestWizardPrintRecordLabel(TransactionCase):
'name': 'ZPL II Label',
'label_id': self.label.id,
'data': '"Test"'})
self.label._on_change_labelary()
self.assertFalse(self.label.labelary_image)
def test_emulation_with_bad_data_compute(self):
@@ -78,9 +76,8 @@ class TestWizardPrintRecordLabel(TransactionCase):
'name': 'ZPL II Label',
'label_id': self.label.id,
'data': 'wrong_data'})
self.label._on_change_labelary()
component.unlink()
self.assertIs(self.label.labelary_image, None)
self.assertIs(self.label.labelary_image, False)
def test_emulation_with_good_data(self):
""" Check if ok """
@@ -92,5 +89,4 @@ class TestWizardPrintRecordLabel(TransactionCase):
'name': 'ZPL II Label',
'label_id': self.label.id,
'data': '"good_data"', })
self.label._on_change_labelary()
self.assertTrue(self.label.labelary_image)

View File

@@ -49,7 +49,11 @@
<field name="name"/>
<field name="component_type"/>
<field name="origin_x"/>
<button name="action_minus_origin_x" type="object" string="-" icon="fa-minus-square"/>
<button name="action_plus_origin_x" type="object" string="+" icon="fa-plus-square"/>
<field name="origin_y"/>
<button name="action_minus_origin_y" type="object" string="-" icon="fa-minus-square"/>
<button name="action_plus_origin_y" type="object" string="+" icon="fa-plus-square"/>
</tree>
<form string="Label Component">
<group>