[IMP] Add a Raw ZPL2 component

This commit is contained in:
Florent de Labarre
2018-01-23 09:38:50 +01:00
committed by Lois Rilo
parent a297ab11b8
commit 041ee4cd82
4 changed files with 41 additions and 7 deletions

View File

@@ -110,6 +110,8 @@ class PrintingLabelZpl2(models.Model):
label_data.font_data( label_data.font_data(
component_offset_x, component_offset_y, component_offset_x, component_offset_y,
barcode_arguments, data) barcode_arguments, data)
elif component.component_type == 'zpl2_raw':
label_data._write_command(data)
elif component.component_type == 'rectangle': elif component.component_type == 'rectangle':
label_data.graphic_box( label_data.graphic_box(
component_offset_x, component_offset_y, { component_offset_x, component_offset_y, {

View File

@@ -11,6 +11,16 @@ try:
except ImportError: except ImportError:
_logger.debug('Cannot `import zpl2`.') _logger.debug('Cannot `import zpl2`.')
DEFAULT_PYTHON_CODE = """# Python One-Liners
# - object: record on which the action is triggered; may be be void
# - page_number: Current Page
# - page_count: Total Page
# - time, datetime: Python libraries
# Exemple : object.name
""
"""
class PrintingLabelZpl2Component(models.Model): class PrintingLabelZpl2Component(models.Model):
_name = 'printing.label.zpl2.component' _name = 'printing.label.zpl2.component'
@@ -45,6 +55,7 @@ class PrintingLabelZpl2Component(models.Model):
(zpl2.BARCODE_EAN_13, 'EAN-13'), (zpl2.BARCODE_EAN_13, 'EAN-13'),
(zpl2.BARCODE_QR_CODE, 'QR Code'), (zpl2.BARCODE_QR_CODE, 'QR Code'),
('sublabel', 'Sublabel'), ('sublabel', 'Sublabel'),
('zpl2_raw', 'ZPL2'),
], string='Type', required=True, default='text', oldname='type', ], string='Type', required=True, default='text', oldname='type',
help='Type of content, simple text or barcode.') help='Type of content, simple text or barcode.')
font = fields.Selection( font = fields.Selection(
@@ -115,8 +126,8 @@ class PrintingLabelZpl2Component(models.Model):
], required=True, default=zpl2.ERROR_CORRECTION_HIGH, ], required=True, default=zpl2.ERROR_CORRECTION_HIGH,
help='Error correction for some barcode types like QR Code.') help='Error correction for some barcode types like QR Code.')
mask_value = fields.Integer(default=7, help='Mask Value, from 0 to 7.') mask_value = fields.Integer(default=7, help='Mask Value, from 0 to 7.')
data = fields.Char( data = fields.Text(
size=256, default='""', required=True, default=DEFAULT_PYTHON_CODE, required=True,
help='Data to print on this component. Resource values can be ' help='Data to print on this component. Resource values can be '
'inserted with %(object.field_name)s.') 'inserted with %(object.field_name)s.')
sublabel_id = fields.Many2one( sublabel_id = fields.Many2one(

View File

@@ -1068,3 +1068,22 @@ class TestPrintingLabelZpl2(TransactionCase):
"^JUR\n" "^JUR\n"
"^XZ") "^XZ")
def test_zpl2_raw_contents_blank(self):
""" Check contents of a image label """
label = self.new_label()
data = '^FO50,50^GB100,100,100^FS'
self.new_component({
'label_id': label.id,
'component_type': 'zpl2_raw',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
'^XA\n'
'^PW480\n'
'^CI28\n'
'^LH10,10\n'
'^FO50,50^GB100,100,100^FS\n'
'^JUR\n'
'^XZ')

View File

@@ -50,20 +50,22 @@
</group> </group>
<group> <group>
<field name="component_type"/> <field name="component_type"/>
<field name="repeat"/> <field name="repeat" attrs="{'invisible': [('component_type', '=', 'zpl2_raw')]}"/>
</group> </group>
<group> <group attrs="{'invisible': [('component_type', '=', 'zpl2_raw')]}">
<field name="origin_x"/> <field name="origin_x"/>
<field name="origin_y"/> <field name="origin_y"/>
</group> </group>
<group> <group>
<field name="data" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="graphic_image" attrs="{'invisible': [('component_type', '!=', 'graphic')]}"/> <field name="graphic_image" attrs="{'invisible': [('component_type', '!=', 'graphic')]}"/>
<field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/> <field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/>
</group> </group>
</group> </group>
<group attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}" string="Data">
<field name="data" widget="ace" options="{'mode': 'python'}" nolabel="1"/>
</group>
<notebook colspan="4"> <notebook colspan="4">
<page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code'))]}"> <page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code', 'zpl2_raw'))]}">
<group> <group>
<field name="height"/> <field name="height"/>
<field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/> <field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/>
@@ -76,7 +78,7 @@
</group> </group>
</page> </page>
<!-- Barcode specific arguments --> <!-- Barcode specific arguments -->
<page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code'))]}"> <page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code', 'zpl2_raw'))]}">
<group> <group>
<field name="check_digits"/> <field name="check_digits"/>
<field name="interpretation_line"/> <field name="interpretation_line"/>