diff --git a/printer_zpl2/models/printing_label_zpl2.py b/printer_zpl2/models/printing_label_zpl2.py index 9a5fbfc..27d668c 100644 --- a/printer_zpl2/models/printing_label_zpl2.py +++ b/printer_zpl2/models/printing_label_zpl2.py @@ -158,6 +158,10 @@ class PrintingLabelZpl2(models.Model): label_offset_x=component_offset_x, label_offset_y=component_offset_y) else: + if component.component_type == zpl2.BARCODE_QR_CODE: + # Adding Control Arguments to QRCode data Label + data = 'MM,A{}'.format(data) + barcode_arguments = dict([ (field_name, component[field_name]) for field_name in [ @@ -172,6 +176,10 @@ class PrintingLabelZpl2(models.Model): zpl2.ARG_TRUNCATE, zpl2.ARG_MODULE_WIDTH, zpl2.ARG_BAR_WIDTH_RATIO, + zpl2.ARG_MODEL, + zpl2.ARG_MAGNIFICATION_FACTOR, + zpl2.ARG_ERROR_CORRECTION, + zpl2.ARG_MASK_VALUE, ] ]) label_data.barcode_data( diff --git a/printer_zpl2/models/printing_label_zpl2_component.py b/printer_zpl2/models/printing_label_zpl2_component.py index 35b4f0c..4d4d220 100644 --- a/printer_zpl2/models/printing_label_zpl2_component.py +++ b/printer_zpl2/models/printing_label_zpl2_component.py @@ -44,6 +44,7 @@ class PrintingLabelZpl2Component(models.Model): (zpl2.BARCODE_UPC_E, 'UPC-E'), (zpl2.BARCODE_CODE_128, 'Code 128'), (zpl2.BARCODE_EAN_13, 'EAN-13'), + (zpl2.BARCODE_QR_CODE, 'QR Code'), ('sublabel', 'Sublabel'), ], string='Type', required=True, default='text', oldname='type', 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.') truncate = fields.Boolean( 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( size=256, default='""', required=True, help='Data to print on this component. Resource values can be ' diff --git a/printer_zpl2/tests/test_printing_label_zpl2.py b/printer_zpl2/tests/test_printing_label_zpl2.py index 37a88b7..b845547 100644 --- a/printer_zpl2/tests/test_printing_label_zpl2.py +++ b/printer_zpl2/tests/test_printing_label_zpl2.py @@ -939,3 +939,38 @@ class TestPrintingLabelZpl2(TransactionCase): '^JUR\n' # Label end '^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)) diff --git a/printer_zpl2/views/printing_label_zpl2.xml b/printer_zpl2/views/printing_label_zpl2.xml index 3b32230..6106e2e 100644 --- a/printer_zpl2/views/printing_label_zpl2.xml +++ b/printer_zpl2/views/printing_label_zpl2.xml @@ -57,7 +57,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -83,6 +83,15 @@ + + + + + + + + +