[IMP] Add QRcode in printer_zpl2 module

This commit is contained in:
Aurimas NAVICKAS
2017-09-06 12:09:04 +02:00
committed by Lois Rilo
parent 9ddd695de1
commit a2d632337c
4 changed files with 72 additions and 2 deletions

View File

@@ -158,6 +158,10 @@ class PrintingLabelZpl2(models.Model):
label_offset_x=component_offset_x, label_offset_x=component_offset_x,
label_offset_y=component_offset_y) label_offset_y=component_offset_y)
else: else:
if component.component_type == zpl2.BARCODE_QR_CODE:
# Adding Control Arguments to QRCode data Label
data = 'MM,A{}'.format(data)
barcode_arguments = dict([ barcode_arguments = dict([
(field_name, component[field_name]) (field_name, component[field_name])
for field_name in [ for field_name in [
@@ -172,6 +176,10 @@ class PrintingLabelZpl2(models.Model):
zpl2.ARG_TRUNCATE, zpl2.ARG_TRUNCATE,
zpl2.ARG_MODULE_WIDTH, zpl2.ARG_MODULE_WIDTH,
zpl2.ARG_BAR_WIDTH_RATIO, zpl2.ARG_BAR_WIDTH_RATIO,
zpl2.ARG_MODEL,
zpl2.ARG_MAGNIFICATION_FACTOR,
zpl2.ARG_ERROR_CORRECTION,
zpl2.ARG_MASK_VALUE,
] ]
]) ])
label_data.barcode_data( label_data.barcode_data(

View File

@@ -44,6 +44,7 @@ class PrintingLabelZpl2Component(models.Model):
(zpl2.BARCODE_UPC_E, 'UPC-E'), (zpl2.BARCODE_UPC_E, 'UPC-E'),
(zpl2.BARCODE_CODE_128, 'Code 128'), (zpl2.BARCODE_CODE_128, 'Code 128'),
(zpl2.BARCODE_EAN_13, 'EAN-13'), (zpl2.BARCODE_EAN_13, 'EAN-13'),
(zpl2.BARCODE_QR_CODE, 'QR Code'),
('sublabel', 'Sublabel'), ('sublabel', 'Sublabel'),
], 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.')
@@ -98,6 +99,23 @@ class PrintingLabelZpl2Component(models.Model):
rows_count = fields.Integer(help='Number of rows to encode.') rows_count = fields.Integer(help='Number of rows to encode.')
truncate = fields.Boolean( truncate = fields.Boolean(
help='Check if you want to truncate the barcode.') help='Check if you want to truncate the barcode.')
model = fields.Selection(
selection=[
(zpl2.MODEL_ORIGINAL, 'Original'),
(zpl2.MODEL_ENHANCED, 'Enhanced'),
], default=zpl2.MODEL_ENHANCED,
help='Barcode model, used by some barcode types like QR Code.')
magnification_factor = fields.Integer(
default=1, help='Magnification Factor, from 1 to 10.')
error_correction = fields.Selection(
selection=[
(zpl2.ERROR_CORRECTION_ULTRA_HIGH, 'Ultra-high Reliability Level'),
(zpl2.ERROR_CORRECTION_HIGH, 'High Reliability Level'),
(zpl2.ERROR_CORRECTION_STANDARD, 'Standard Level'),
(zpl2.ERROR_CORRECTION_HIGH_DENSITY, 'High Density Level'),
], required=True, default=zpl2.ERROR_CORRECTION_HIGH,
help='Error correction for some barcode types like QR Code.')
mask_value = fields.Integer(default=7, help='Mask Value, from 0 to 7.')
data = fields.Char( data = fields.Char(
size=256, default='""', required=True, size=256, default='""', required=True,
help='Data to print on this component. Resource values can be ' help='Data to print on this component. Resource values can be '

View File

@@ -939,3 +939,38 @@ class TestPrintingLabelZpl2(TransactionCase):
'^JUR\n' '^JUR\n'
# Label end # Label end
'^XZ'.format(contents=data)) '^XZ'.format(contents=data))
def test_qrcode_barcode_label_contents(self):
""" Check contents of a qr code barcode label """
label = self.new_label()
data = 'Some text'
self.new_component({
'label_id': label.id,
'component_type': 'qr_code',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
self.assertEqual(
contents,
# Label start
'^XA\n'
# Print width
'^PW480\n'
# UTF-8 encoding
'^CI28\n'
# Label position
'^LH10,10\n'
# Barcode default format
'^BY2,3.0'
# Component position
'^FO10,10'
# Component format
'^BQN,2,1,Q,7'
# Component contents
'^FDMM,A{contents}'
# Component end
'^FS\n'
# Recall last saved parameters
'^JUR\n'
# Label end
'^XZ'.format(contents=data))

View File

@@ -57,7 +57,7 @@
</group> </group>
</group> </group>
<notebook colspan="4"> <notebook colspan="4">
<page string="Format" attrs="{'invisible': [('component_type', '=', ('sublabel'))]}"> <page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code'))]}">
<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'))]}"/>
@@ -70,7 +70,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'))]}"> <page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code'))]}">
<group> <group>
<field name="check_digits"/> <field name="check_digits"/>
<field name="interpretation_line"/> <field name="interpretation_line"/>
@@ -83,6 +83,15 @@
<field name="truncate"/> <field name="truncate"/>
</group> </group>
</page> </page>
<!-- 2D Barcode arguments -->
<page string="2D Barcode Arguments" attrs="{'invisible': [('component_type', '!=', 'qr_code')]}">
<group>
<field name="model"/>
<field name="magnification_factor"/>
<field name="error_correction"/>
<field name="mask_value"/>
</group>
</page>
<!-- Text block specific arguments --> <!-- Text block specific arguments -->
<page string="Text Block Format" attrs="{'invisible': ['|', ('component_type', '!=', 'text'), ('in_block', '=', False)]}"> <page string="Text Block Format" attrs="{'invisible': ['|', ('component_type', '!=', 'text'), ('in_block', '=', False)]}">
<group> <group>