mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] print_zpl2 : quick move
This commit is contained in:
@@ -55,7 +55,8 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
extra = fields.Text(string="Extra", default='{}')
|
extra = fields.Text(string="Extra", default='{}')
|
||||||
printer_id = fields.Many2one(
|
printer_id = fields.Many2one(
|
||||||
comodel_name='printing.printer', string='Printer')
|
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(
|
labelary_dpmm = fields.Selection(
|
||||||
selection=[
|
selection=[
|
||||||
('6dpmm', '6dpmm (152 pdi)'),
|
('6dpmm', '6dpmm (152 pdi)'),
|
||||||
@@ -312,15 +313,19 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
if record:
|
if record:
|
||||||
label.print_label(label.printer_id, record, **extra)
|
label.print_label(label.printer_id, record, **extra)
|
||||||
|
|
||||||
@api.onchange(
|
@api.depends(
|
||||||
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
|
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
|
||||||
'component_ids', 'origin_x', 'origin_y')
|
'component_ids', 'origin_x', 'origin_y', 'test_labelary_mode')
|
||||||
def _on_change_labelary(self):
|
def _compute_labelary_image(self):
|
||||||
|
for label in self:
|
||||||
|
label.labelary_image = label._generate_labelary_image()
|
||||||
|
|
||||||
|
def _generate_labelary_image(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if not(self.test_labelary_mode and self.record_id and
|
if not(self.test_labelary_mode and self.record_id and
|
||||||
self.labelary_width and self.labelary_height and
|
self.labelary_width and self.labelary_height and
|
||||||
self.labelary_dpmm and self.component_ids):
|
self.labelary_dpmm and self.component_ids):
|
||||||
return
|
return False
|
||||||
record = self._get_record()
|
record = self._get_record()
|
||||||
if record:
|
if record:
|
||||||
# If case there an error (in the data field with the safe_eval
|
# 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))
|
new_im.paste(im, (1, 1))
|
||||||
imgByteArr = io.BytesIO()
|
imgByteArr = io.BytesIO()
|
||||||
new_im.save(imgByteArr, format='PNG')
|
new_im.save(imgByteArr, format='PNG')
|
||||||
self.labelary_image = base64.b64encode(
|
return base64.b64encode(imgByteArr.getvalue())
|
||||||
imgByteArr.getvalue())
|
|
||||||
else:
|
else:
|
||||||
return {'warning': {
|
_logger.warning(
|
||||||
'title': _('Error with Labelary API.'),
|
_("Error with Labelary API. %s") % response.status_code)
|
||||||
'message': response.status_code,
|
|
||||||
}}
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.labelary_image = False
|
_logger.warning(_("Error with Labelary API. %s") % e)
|
||||||
return {'warning': {
|
return False
|
||||||
'title': _('Some thing is wrong.'),
|
|
||||||
'message': e,
|
|
||||||
}}
|
|
||||||
|
|||||||
@@ -184,3 +184,19 @@ class PrintingLabelZpl2Component(models.Model):
|
|||||||
string='Image', attachment=True,
|
string='Image', attachment=True,
|
||||||
help='This field holds a static image to print. '
|
help='This field holds a static image to print. '
|
||||||
'If not set, the data field is evaluated.')
|
'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
|
||||||
|
|||||||
@@ -1135,3 +1135,22 @@ class TestPrintingLabelZpl2(TransactionCase):
|
|||||||
'^LH10,10\n'
|
'^LH10,10\n'
|
||||||
'^JUR\n'
|
'^JUR\n'
|
||||||
'^XZ')
|
'^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)
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ class TestWizardPrintRecordLabel(TransactionCase):
|
|||||||
def test_emulation_without_params(self):
|
def test_emulation_without_params(self):
|
||||||
""" Check if not execute next if not in this mode """
|
""" Check if not execute next if not in this mode """
|
||||||
self.label.test_labelary_mode = False
|
self.label.test_labelary_mode = False
|
||||||
self.label._on_change_labelary()
|
self.assertIs(self.label.labelary_image, False)
|
||||||
self.assertIs(self.label.labelary_image, None)
|
|
||||||
|
|
||||||
def test_emulation_with_bad_header(self):
|
def test_emulation_with_bad_header(self):
|
||||||
""" Check if bad header """
|
""" Check if bad header """
|
||||||
@@ -65,7 +64,6 @@ class TestWizardPrintRecordLabel(TransactionCase):
|
|||||||
'name': 'ZPL II Label',
|
'name': 'ZPL II Label',
|
||||||
'label_id': self.label.id,
|
'label_id': self.label.id,
|
||||||
'data': '"Test"'})
|
'data': '"Test"'})
|
||||||
self.label._on_change_labelary()
|
|
||||||
self.assertFalse(self.label.labelary_image)
|
self.assertFalse(self.label.labelary_image)
|
||||||
|
|
||||||
def test_emulation_with_bad_data_compute(self):
|
def test_emulation_with_bad_data_compute(self):
|
||||||
@@ -78,9 +76,8 @@ class TestWizardPrintRecordLabel(TransactionCase):
|
|||||||
'name': 'ZPL II Label',
|
'name': 'ZPL II Label',
|
||||||
'label_id': self.label.id,
|
'label_id': self.label.id,
|
||||||
'data': 'wrong_data'})
|
'data': 'wrong_data'})
|
||||||
self.label._on_change_labelary()
|
|
||||||
component.unlink()
|
component.unlink()
|
||||||
self.assertIs(self.label.labelary_image, None)
|
self.assertIs(self.label.labelary_image, False)
|
||||||
|
|
||||||
def test_emulation_with_good_data(self):
|
def test_emulation_with_good_data(self):
|
||||||
""" Check if ok """
|
""" Check if ok """
|
||||||
@@ -92,5 +89,4 @@ class TestWizardPrintRecordLabel(TransactionCase):
|
|||||||
'name': 'ZPL II Label',
|
'name': 'ZPL II Label',
|
||||||
'label_id': self.label.id,
|
'label_id': self.label.id,
|
||||||
'data': '"good_data"', })
|
'data': '"good_data"', })
|
||||||
self.label._on_change_labelary()
|
|
||||||
self.assertTrue(self.label.labelary_image)
|
self.assertTrue(self.label.labelary_image)
|
||||||
|
|||||||
@@ -49,7 +49,11 @@
|
|||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="component_type"/>
|
<field name="component_type"/>
|
||||||
<field name="origin_x"/>
|
<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"/>
|
<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>
|
</tree>
|
||||||
<form string="Label Component">
|
<form string="Label Component">
|
||||||
<group>
|
<group>
|
||||||
|
|||||||
Reference in New Issue
Block a user