[MIG] printer_zpl2: Migration to 13.0

This commit is contained in:
Rod Schouteden
2019-09-30 15:35:28 +02:00
committed by mreficent
parent fe3208cd64
commit 4291cca6ca
23 changed files with 2074 additions and 1345 deletions

View File

@@ -1,14 +1,16 @@
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
import base64
import datetime
import io
import logging
import time
import requests
from PIL import Image, ImageOps
from odoo import api, exceptions, fields, models, _
from odoo import _, api, exceptions, fields, models
from odoo.tools.safe_eval import safe_eval
_logger = logging.getLogger(__name__)
@@ -16,59 +18,248 @@ _logger = logging.getLogger(__name__)
try:
import zpl2
except ImportError:
_logger.debug('Cannot `import zpl2`.')
_logger.debug("Cannot `import zpl2`.")
class PrintingLabelZpl2(models.Model):
_name = 'printing.label.zpl2'
_description = 'ZPL II Label'
_order = 'model_id, name, id'
_name = "printing.label.zpl2"
_description = "ZPL II Label"
_order = "model_id, name, id"
name = fields.Char(required=True, help='Label Name.')
name = fields.Char(required=True, help="Label Name.")
active = fields.Boolean(default=True)
description = fields.Char(help='Long description for this label.')
description = fields.Char(help="Long description for this label.")
model_id = fields.Many2one(
comodel_name='ir.model', string='Model', required=True,
help='Model used to print this label.')
comodel_name="ir.model",
string="Model",
required=True,
help="Model used to print this label.",
)
origin_x = fields.Integer(
required=True, default=10,
help='Origin point of the contents in the label, X coordinate.')
required=True,
default=10,
help="Origin point of the contents in the label, X coordinate.",
)
origin_y = fields.Integer(
required=True, default=10,
help='Origin point of the contents in the label, Y coordinate.')
required=True,
default=10,
help="Origin point of the contents in the label, Y coordinate.",
)
width = fields.Integer(
required=True, default=480,
help='Width of the label, will be set on the printer before printing.')
required=True,
default=480,
help="Width of the label, will be set on the printer before printing.",
)
component_ids = fields.One2many(
comodel_name='printing.label.zpl2.component', inverse_name='label_id',
string='Label Components',
help='Components which will be printed on the label.', copy=True)
comodel_name="printing.label.zpl2.component",
inverse_name="label_id",
string="Label Components",
help="Components which will be printed on the label.",
copy=True,
)
restore_saved_config = fields.Boolean(
string="Restore printer's configuration",
help="Restore printer's saved configuration and end of each label ",
default=True)
default=True,
)
action_window_id = fields.Many2one(
comodel_name='ir.actions.act_window', string='Action', readonly=True)
test_print_mode = fields.Boolean(string='Mode Print')
test_labelary_mode = fields.Boolean(string='Mode Labelary')
record_id = fields.Integer(string='Record ID', default=1)
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)
comodel_name="ir.actions.act_window", string="Action", readonly=True
)
test_print_mode = fields.Boolean(string="Mode Print")
test_labelary_mode = fields.Boolean(string="Mode Labelary")
record_id = fields.Integer(string="Record ID", default=1)
extra = fields.Text(default="{}")
printer_id = fields.Many2one(comodel_name="printing.printer", string="Printer")
labelary_image = fields.Binary(string="Image from Labelary", readonly=True)
labelary_dpmm = fields.Selection(
selection=[
('6dpmm', '6dpmm (152 pdi)'),
('8dpmm', '8dpmm (203 dpi)'),
('12dpmm', '12dpmm (300 pdi)'),
('24dpmm', '24dpmm (600 dpi)'),
], string='Print density', required=True, default='8dpmm')
labelary_width = fields.Float(string='Width in mm', default=140)
labelary_height = fields.Float(string='Height in mm', default=70)
("6dpmm", "6dpmm (152 pdi)"),
("8dpmm", "8dpmm (203 dpi)"),
("12dpmm", "12dpmm (300 pdi)"),
("24dpmm", "24dpmm (600 dpi)"),
],
string="Print density",
required=True,
default="8dpmm",
)
labelary_width = fields.Float(string="Width in mm", default=140)
labelary_height = fields.Float(string="Height in mm", default=70)
def _generate_zpl2_components_data_repeatable(
self, component, data, label_offset_x, label_offset_y
):
to_print = []
# Generate a list of elements if the component is repeatable
for idx in range(
component.repeat_offset, component.repeat_offset + component.repeat_count
):
printed_data = data
# Pick the right value if data is a collection
if isinstance(data, (list, tuple, set, models.BaseModel)):
# If we reached the end of data, quit the loop
if idx >= len(data):
break
# Set the real data to display
printed_data = data[idx]
position = idx - component.repeat_offset
to_print.append(
(
component,
printed_data,
label_offset_x + component.repeat_offset_x * position,
label_offset_y + component.repeat_offset_y * position,
)
)
return to_print
def _component_type_selector(
self,
component,
label_data,
component_offset_x,
component_offset_y,
offset_x,
offset_y,
data,
):
if component.component_type == "text":
barcode_arguments = {
field_name: component[field_name]
for field_name in [
zpl2.ARG_FONT,
zpl2.ARG_ORIENTATION,
zpl2.ARG_HEIGHT,
zpl2.ARG_WIDTH,
zpl2.ARG_REVERSE_PRINT,
zpl2.ARG_IN_BLOCK,
zpl2.ARG_BLOCK_WIDTH,
zpl2.ARG_BLOCK_LINES,
zpl2.ARG_BLOCK_SPACES,
zpl2.ARG_BLOCK_JUSTIFY,
zpl2.ARG_BLOCK_LEFT_MARGIN,
]
}
label_data.font_data(
component_offset_x, component_offset_y, barcode_arguments, data
)
elif component.component_type == "zpl2_raw":
label_data._write_command(data)
elif component.component_type == "rectangle":
label_data.graphic_box(
component_offset_x,
component_offset_y,
{
zpl2.ARG_WIDTH: component.width,
zpl2.ARG_HEIGHT: component.height,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
zpl2.ARG_ROUNDING: component.rounding,
},
)
elif component.component_type == "diagonal":
label_data.graphic_diagonal_line(
component_offset_x,
component_offset_y,
{
zpl2.ARG_WIDTH: component.width,
zpl2.ARG_HEIGHT: component.height,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
zpl2.ARG_DIAGONAL_ORIENTATION: component.diagonal_orientation,
},
)
elif component.component_type == "graphic":
# During the on_change don't take the bin_size
image = (
component.with_context(bin_size_graphic_image=False).graphic_image
or data
)
try:
pil_image = Image.open(io.BytesIO(base64.b64decode(image))).convert(
"RGB"
)
except Exception:
return
if component.width and component.height:
pil_image = pil_image.resize((component.width, component.height))
# Invert the colors
if component.reverse_print:
pil_image = ImageOps.invert(pil_image)
# Rotation (PIL rotates counter clockwise)
if component.orientation == zpl2.ORIENTATION_ROTATED:
pil_image = pil_image.transpose(Image.ROTATE_270)
elif component.orientation == zpl2.ORIENTATION_INVERTED:
pil_image = pil_image.transpose(Image.ROTATE_180)
elif component.orientation == zpl2.ORIENTATION_BOTTOM_UP:
pil_image = pil_image.transpose(Image.ROTATE_90)
label_data.graphic_field(component_offset_x, component_offset_y, pil_image)
elif component.component_type == "circle":
label_data.graphic_circle(
component_offset_x,
component_offset_y,
{
zpl2.ARG_DIAMETER: component.width,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
},
)
elif component.component_type == "sublabel":
component_offset_x += component.sublabel_id.origin_x
component_offset_y += component.sublabel_id.origin_y
component.sublabel_id._generate_zpl2_components_data(
label_data,
data,
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 = "{}A,{}".format(component.error_correction, data)
barcode_arguments = {
field_name: component[field_name]
for field_name in [
zpl2.ARG_ORIENTATION,
zpl2.ARG_CHECK_DIGITS,
zpl2.ARG_HEIGHT,
zpl2.ARG_INTERPRETATION_LINE,
zpl2.ARG_INTERPRETATION_LINE_ABOVE,
zpl2.ARG_SECURITY_LEVEL,
zpl2.ARG_COLUMNS_COUNT,
zpl2.ARG_ROWS_COUNT,
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(
component.origin_x + offset_x,
component.origin_y + offset_y,
component.component_type,
barcode_arguments,
data,
)
def _generate_zpl2_components_data(
self, label_data, record, page_number=1, page_count=1,
label_offset_x=0, label_offset_y=0, **extra):
self,
label_data,
record,
page_number=1,
page_count=1,
label_offset_x=0,
label_offset_y=0,
**extra
):
self.ensure_one()
# Add all elements to print in a list of tuples :
@@ -76,161 +267,41 @@ class PrintingLabelZpl2(models.Model):
to_print = []
for component in self.component_ids:
eval_args = extra
eval_args.update({
'object': record,
'page_number': str(page_number + 1),
'page_count': str(page_count),
'time': time,
'datetime': datetime,
})
data = safe_eval(component.data, eval_args) or ''
eval_args.update(
{
"object": record,
"page_number": str(page_number + 1),
"page_count": str(page_count),
"time": time,
"datetime": datetime,
}
)
data = safe_eval(component.data, eval_args) or ""
if data == 'component_not_show':
if isinstance(data, str) and data == "component_not_show":
continue
# Generate a list of elements if the component is repeatable
for idx in range(
component.repeat_offset,
component.repeat_offset + component.repeat_count):
printed_data = data
# Pick the right value if data is a collection
if isinstance(data, (list, tuple, set, models.BaseModel)):
# If we reached the end of data, quit the loop
if idx >= len(data):
break
# Set the real data to display
printed_data = data[idx]
position = idx - component.repeat_offset
to_print.append((
component, printed_data,
label_offset_x + component.repeat_offset_x * position,
label_offset_y + component.repeat_offset_y * position,
))
to_print = self._generate_zpl2_components_data_repeatable(
component, data, label_offset_x, label_offset_y
)
for (component, data, offset_x, offset_y) in to_print:
component_offset_x = component.origin_x + offset_x
component_offset_y = component.origin_y + offset_y
if component.component_type == 'text':
barcode_arguments = dict([
(field_name, component[field_name])
for field_name in [
zpl2.ARG_FONT,
zpl2.ARG_ORIENTATION,
zpl2.ARG_HEIGHT,
zpl2.ARG_WIDTH,
zpl2.ARG_REVERSE_PRINT,
zpl2.ARG_IN_BLOCK,
zpl2.ARG_BLOCK_WIDTH,
zpl2.ARG_BLOCK_LINES,
zpl2.ARG_BLOCK_SPACES,
zpl2.ARG_BLOCK_JUSTIFY,
zpl2.ARG_BLOCK_LEFT_MARGIN,
]
])
label_data.font_data(
component_offset_x, component_offset_y,
barcode_arguments, data)
elif component.component_type == 'zpl2_raw':
label_data._write_command(data)
elif component.component_type == 'rectangle':
label_data.graphic_box(
component_offset_x, component_offset_y, {
zpl2.ARG_WIDTH: component.width,
zpl2.ARG_HEIGHT: component.height,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
zpl2.ARG_ROUNDING: component.rounding,
})
elif component.component_type == 'diagonal':
label_data.graphic_diagonal_line(
component_offset_x, component_offset_y, {
zpl2.ARG_WIDTH: component.width,
zpl2.ARG_HEIGHT: component.height,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
zpl2.ARG_DIAGONAL_ORIENTATION:
component.diagonal_orientation,
})
elif component.component_type == 'graphic':
# During the on_change don't take the bin_size
image = component.with_context(bin_size_graphic_image=False)\
.graphic_image or data
try:
pil_image = Image.open(io.BytesIO(
base64.b64decode(image))).convert('RGB')
except Exception:
continue
if component.width and component.height:
pil_image = pil_image.resize(
(component.width, component.height))
# Invert the colors
if component.reverse_print:
pil_image = ImageOps.invert(pil_image)
# Rotation (PIL rotates counter clockwise)
if component.orientation == zpl2.ORIENTATION_ROTATED:
pil_image = pil_image.transpose(Image.ROTATE_270)
elif component.orientation == zpl2.ORIENTATION_INVERTED:
pil_image = pil_image.transpose(Image.ROTATE_180)
elif component.orientation == zpl2.ORIENTATION_BOTTOM_UP:
pil_image = pil_image.transpose(Image.ROTATE_90)
label_data.graphic_field(
component_offset_x, component_offset_y,
pil_image
)
elif component.component_type == 'circle':
label_data.graphic_circle(
component_offset_x, component_offset_y, {
zpl2.ARG_DIAMETER: component.width,
zpl2.ARG_THICKNESS: component.thickness,
zpl2.ARG_COLOR: component.color,
})
elif component.component_type == 'sublabel':
component_offset_x += component.sublabel_id.origin_x
component_offset_y += component.sublabel_id.origin_y
component.sublabel_id._generate_zpl2_components_data(
label_data, data,
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 = '{}A,{}'.format(component.error_correction, data)
barcode_arguments = dict([
(field_name, component[field_name])
for field_name in [
zpl2.ARG_ORIENTATION,
zpl2.ARG_CHECK_DIGITS,
zpl2.ARG_HEIGHT,
zpl2.ARG_INTERPRETATION_LINE,
zpl2.ARG_INTERPRETATION_LINE_ABOVE,
zpl2.ARG_SECURITY_LEVEL,
zpl2.ARG_COLUMNS_COUNT,
zpl2.ARG_ROWS_COUNT,
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(
component.origin_x + offset_x,
component.origin_y + offset_y,
component.component_type, barcode_arguments, data)
self._component_type_selector(
component,
label_data,
component_offset_x,
component_offset_y,
offset_x,
offset_y,
data,
)
def _generate_zpl2_data(self, record, page_count=1, **extra):
self.ensure_one()
label_data = zpl2.Zpl2()
labelary_emul = extra.get('labelary_emul', False)
labelary_emul = extra.get("labelary_emul", False)
for page_number in range(page_count):
# Initialize printer's configuration
label_data.label_start()
@@ -241,8 +312,12 @@ class PrintingLabelZpl2(models.Model):
label_data.label_home(self.origin_x, self.origin_y)
self._generate_zpl2_components_data(
label_data, record, page_number=page_number,
page_count=page_count, **extra)
label_data,
record,
page_number=page_number,
page_count=page_count,
**extra
)
# Restore printer's configuration and end the label
if self.restore_saved_config:
@@ -255,51 +330,53 @@ class PrintingLabelZpl2(models.Model):
for label in self:
if record._name != label.model_id.model:
raise exceptions.UserError(
_('This label cannot be used on {model}').format(
model=record._name))
_("This label cannot be used on {model}").format(model=record._name)
)
# Send the label to printer
label_contents = label._generate_zpl2_data(
record, page_count=page_count, **extra)
record, page_count=page_count, **extra
)
printer.print_document(
report=None, content=label_contents, doc_format='raw')
report=None, content=label_contents, doc_format="raw"
)
return True
def create_action(self):
for label in self.filtered(lambda record: not record.action_window_id):
label.action_window_id = self.env['ir.actions.act_window'].create({
'name': _('Print Label'),
'src_model': label.model_id.model,
'binding_model_id': label.model_id.id,
'res_model': 'wizard.print.record.label',
'view_mode': 'form',
'target': 'new',
'binding_type': 'action',
})
label.action_window_id = self.env["ir.actions.act_window"].create(
{
"name": _("Print Label"),
"binding_model_id": label.model_id.id,
"res_model": "wizard.print.record.label",
"view_mode": "form",
"target": "new",
"binding_type": "action",
}
)
return True
def unlink_action(self):
self.mapped('action_window_id').unlink()
self.mapped("action_window_id").unlink()
def import_zpl2(self):
self.ensure_one()
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'wizard.import.zpl2',
'type': 'ir.actions.act_window',
'target': 'new',
'context': {'default_label_id': self.id},
"view_mode": "form",
"res_model": "wizard.import.zpl2",
"type": "ir.actions.act_window",
"target": "new",
"context": {"default_label_id": self.id},
}
def _get_record(self):
self.ensure_one()
Obj = self.env[self.model_id.model]
record = Obj.search([('id', '=', self.record_id)], limit=1)
record = Obj.search([("id", "=", self.record_id)], limit=1)
if not record:
record = Obj.search([], limit=1, order='id desc')
record = Obj.search([], limit=1, order="id desc")
self.record_id = record.id
return record
@@ -308,58 +385,66 @@ class PrintingLabelZpl2(models.Model):
for label in self:
if label.test_print_mode and label.record_id and label.printer_id:
record = label._get_record()
extra = safe_eval(label.extra, {'env': self.env})
extra = safe_eval(label.extra, {"env": self.env})
if record:
label.print_label(label.printer_id, record, **extra)
@api.onchange(
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
'component_ids', 'origin_x', 'origin_y')
"record_id",
"labelary_dpmm",
"labelary_width",
"labelary_height",
"component_ids",
"origin_x",
"origin_y",
)
def _on_change_labelary(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):
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
record = self._get_record()
if record:
# If case there an error (in the data field with the safe_eval
# for exemple) the new component or the update is not lost.
try:
url = 'http://api.labelary.com/v1/printers/' \
'{dpmm}/labels/{width}x{height}/0/'
url = (
"http://api.labelary.com/v1/printers/"
"{dpmm}/labels/{width}x{height}/0/"
)
width = round(self.labelary_width / 25.4, 2)
height = round(self.labelary_height / 25.4, 2)
url = url.format(
dpmm=self.labelary_dpmm, width=width, height=height)
extra = safe_eval(self.extra, {'env': self.env})
zpl_file = self._generate_zpl2_data(
record, labelary_emul=True, **extra)
files = {'file': zpl_file}
headers = {'Accept': 'image/png'}
response = requests.post(
url, headers=headers, files=files, stream=True)
url = url.format(dpmm=self.labelary_dpmm, width=width, height=height)
extra = safe_eval(self.extra, {"env": self.env})
zpl_file = self._generate_zpl2_data(record, labelary_emul=True, **extra)
files = {"file": zpl_file}
headers = {"Accept": "image/png"}
response = requests.post(url, headers=headers, files=files, stream=True)
if response.status_code == 200:
# Add a padd
im = Image.open(io.BytesIO(response.content))
im_size = im.size
new_im = Image.new(
'RGB', (im_size[0] + 2, im_size[1] + 2),
(164, 164, 164))
"RGB", (im_size[0] + 2, im_size[1] + 2), (164, 164, 164)
)
new_im.paste(im, (1, 1))
imgByteArr = io.BytesIO()
new_im.save(imgByteArr, format='PNG')
self.labelary_image = base64.b64encode(
imgByteArr.getvalue())
new_im.save(imgByteArr, format="PNG")
self.labelary_image = base64.b64encode(imgByteArr.getvalue())
else:
return {'warning': {
'title': _('Error with Labelary API.'),
'message': response.status_code,
}}
return {
"warning": {
"title": _("Error with Labelary API."),
"message": response.status_code,
}
}
except Exception as e:
self.labelary_image = False
return {'warning': {
'title': _('Some thing is wrong.'),
'message': e,
}}
return {"warning": {"title": _("Some thing is wrong."), "message": e}}

View File

@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import fields, models
_logger = logging.getLogger(__name__)
@@ -9,7 +10,7 @@ _logger = logging.getLogger(__name__)
try:
import zpl2
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
@@ -25,162 +26,208 @@ DEFAULT_PYTHON_CODE = """# Python One-Liners
class PrintingLabelZpl2Component(models.Model):
_name = 'printing.label.zpl2.component'
_description = 'ZPL II Label Component'
_order = 'sequence, id'
_name = "printing.label.zpl2.component"
_description = "ZPL II Label Component"
_order = "sequence, id"
label_id = fields.Many2one(
comodel_name='printing.label.zpl2', string='Label',
required=True, ondelete='cascade', help='Label using this component.')
sequence = fields.Integer(help='Order used to print the elements.')
name = fields.Char(required=True, help='Name of the component.')
comodel_name="printing.label.zpl2",
string="Label",
required=True,
ondelete="cascade",
help="Label using this component.",
)
sequence = fields.Integer(help="Order used to print the elements.")
name = fields.Char(required=True, help="Name of the component.")
origin_x = fields.Integer(
required=True, default=10,
help='Origin point of the component in the label, X coordinate.')
required=True,
default=10,
help="Origin point of the component in the label, X coordinate.",
)
origin_y = fields.Integer(
required=True, default=10,
help='Origin point of the component in the label, Y coordinate.')
required=True,
default=10,
help="Origin point of the component in the label, Y coordinate.",
)
component_type = fields.Selection(
selection=[
('text', 'Text'),
('rectangle', 'Rectangle / Line'),
('diagonal', 'Diagonal Line'),
('circle', 'Circle'),
('graphic', 'Graphic'),
(zpl2.BARCODE_CODE_11, 'Code 11'),
(zpl2.BARCODE_INTERLEAVED_2_OF_5, 'Interleaved 2 of 5'),
(zpl2.BARCODE_CODE_39, 'Code 39'),
(zpl2.BARCODE_CODE_49, 'Code 49'),
(zpl2.BARCODE_PDF417, 'PDF417'),
(zpl2.BARCODE_EAN_8, 'EAN-8'),
(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'),
('zpl2_raw', 'ZPL2'),
], string='Type', required=True, default='text', oldname='type',
help='Type of content, simple text or barcode.')
("text", "Text"),
("rectangle", "Rectangle / Line"),
("diagonal", "Diagonal Line"),
("circle", "Circle"),
("graphic", "Graphic"),
(zpl2.BARCODE_CODE_11, "Code 11"),
(zpl2.BARCODE_INTERLEAVED_2_OF_5, "Interleaved 2 of 5"),
(zpl2.BARCODE_CODE_39, "Code 39"),
(zpl2.BARCODE_CODE_49, "Code 49"),
(zpl2.BARCODE_PDF417, "PDF417"),
(zpl2.BARCODE_EAN_8, "EAN-8"),
(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"),
("zpl2_raw", "ZPL2"),
],
string="Type",
required=True,
default="text",
help="Type of content, simple text or barcode.",
)
font = fields.Selection(
selection=[
(zpl2.FONT_DEFAULT, 'Default'),
(zpl2.FONT_9X5, '9x5'),
(zpl2.FONT_11X7, '11x7'),
(zpl2.FONT_18X10, '18x10'),
(zpl2.FONT_28X15, '28x15'),
(zpl2.FONT_26X13, '26x13'),
(zpl2.FONT_60X40, '60x40'),
(zpl2.FONT_21X13, '21x13'),
], required=True, default=zpl2.FONT_DEFAULT,
help='Font to use, for text only.')
thickness = fields.Integer(help='Thickness of the line to draw.')
(zpl2.FONT_DEFAULT, "Default"),
(zpl2.FONT_9X5, "9x5"),
(zpl2.FONT_11X7, "11x7"),
(zpl2.FONT_18X10, "18x10"),
(zpl2.FONT_28X15, "28x15"),
(zpl2.FONT_26X13, "26x13"),
(zpl2.FONT_60X40, "60x40"),
(zpl2.FONT_21X13, "21x13"),
],
required=True,
default=zpl2.FONT_DEFAULT,
help="Font to use, for text only.",
)
thickness = fields.Integer(help="Thickness of the line to draw.")
color = fields.Selection(
selection=[
(zpl2.COLOR_BLACK, 'Black'),
(zpl2.COLOR_WHITE, 'White'),
], default=zpl2.COLOR_BLACK,
help='Color of the line to draw.')
selection=[(zpl2.COLOR_BLACK, "Black"), (zpl2.COLOR_WHITE, "White")],
default=zpl2.COLOR_BLACK,
help="Color of the line to draw.",
)
orientation = fields.Selection(
selection=[
(zpl2.ORIENTATION_NORMAL, 'Normal'),
(zpl2.ORIENTATION_ROTATED, 'Rotated'),
(zpl2.ORIENTATION_INVERTED, 'Inverted'),
(zpl2.ORIENTATION_BOTTOM_UP, 'Read from Bottom up'),
], required=True, default=zpl2.ORIENTATION_NORMAL,
help='Orientation of the barcode.')
(zpl2.ORIENTATION_NORMAL, "Normal"),
(zpl2.ORIENTATION_ROTATED, "Rotated"),
(zpl2.ORIENTATION_INVERTED, "Inverted"),
(zpl2.ORIENTATION_BOTTOM_UP, "Read from Bottom up"),
],
required=True,
default=zpl2.ORIENTATION_NORMAL,
help="Orientation of the barcode.",
)
diagonal_orientation = fields.Selection(
selection=[
(zpl2.DIAGONAL_ORIENTATION_LEFT, 'Left (\\)'),
(zpl2.DIAGONAL_ORIENTATION_RIGHT, 'Right (/)'),
], default=zpl2.DIAGONAL_ORIENTATION_LEFT,
help='Orientation of the diagonal line.')
(zpl2.DIAGONAL_ORIENTATION_LEFT, "Left (\\)"),
(zpl2.DIAGONAL_ORIENTATION_RIGHT, "Right (/)"),
],
default=zpl2.DIAGONAL_ORIENTATION_LEFT,
help="Orientation of the diagonal line.",
)
check_digits = fields.Boolean(
help='Check if you want to compute and print the check digit.')
help="Check if you want to compute and print the check digit."
)
height = fields.Integer(
help='Height of the printed component. For a text component, height '
'of a single character.')
help="Height of the printed component. For a text component, height "
"of a single character."
)
width = fields.Integer(
help='Width of the printed component. For a text component, width of '
'a single character.')
rounding = fields.Integer(
help='Rounding of the printed rectangle corners.')
help="Width of the printed component. For a text component, width of "
"a single character."
)
rounding = fields.Integer(help="Rounding of the printed rectangle corners.")
interpretation_line = fields.Boolean(
help='Check if you want the interpretation line to be printed.')
help="Check if you want the interpretation line to be printed."
)
interpretation_line_above = fields.Boolean(
help='Check if you want the interpretation line to be printed above '
'the barcode.')
module_width = fields.Integer(
default=2, help='Module width for the barcode.')
help="Check if you want the interpretation line to be printed above "
"the barcode."
)
module_width = fields.Integer(default=2, help="Module width for the barcode.")
bar_width_ratio = fields.Float(
default=3.0, help='Ratio between wide bar and narrow bar.')
security_level = fields.Integer(help='Security level for error detection.')
columns_count = fields.Integer(help='Number of data columns to encode.')
rows_count = fields.Integer(help='Number of rows to encode.')
truncate = fields.Boolean(
help='Check if you want to truncate the barcode.')
default=3.0, help="Ratio between wide bar and narrow bar."
)
security_level = fields.Integer(help="Security level for error detection.")
columns_count = fields.Integer(help="Number of data columns to encode.")
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.')
(str(zpl2.MODEL_ORIGINAL), "Original"),
(str(zpl2.MODEL_ENHANCED), "Enhanced"),
],
default=str(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.')
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.')
(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.Text(
default=DEFAULT_PYTHON_CODE, required=True,
help='Data to print on this component. Resource values can be '
'inserted with %(object.field_name)s.')
default=DEFAULT_PYTHON_CODE,
required=True,
help="Data to print on this component. Resource values can be "
"inserted with %(object.field_name)s.",
)
sublabel_id = fields.Many2one(
comodel_name='printing.label.zpl2', string='Sublabel',
help='Another label to include into this one as a component. '
'This allows to define reusable labels parts.')
comodel_name="printing.label.zpl2",
string="Sublabel",
help="Another label to include into this one as a component. "
"This allows to define reusable labels parts.",
)
repeat = fields.Boolean(
string='Repeatable',
help='Check this box to repeat this component on the label.')
string="Repeatable",
help="Check this box to repeat this component on the label.",
)
repeat_offset = fields.Integer(
default=0,
help='Number of elements to skip when reading a list of elements.')
default=0, help="Number of elements to skip when reading a list of elements."
)
repeat_count = fields.Integer(
default=1,
help='Maximum count of repeats of the component.')
default=1, help="Maximum count of repeats of the component."
)
repeat_offset_x = fields.Integer(
help='X coordinate offset between each occurence of this component on '
'the label.')
help="X coordinate offset between each occurence of this component on "
"the label."
)
repeat_offset_y = fields.Integer(
help='Y coordinate offset between each occurence of this component on '
'the label.')
help="Y coordinate offset between each occurence of this component on "
"the label."
)
reverse_print = fields.Boolean(
help='If checked, the data will be printed in the inverse color of '
'the background.')
help="If checked, the data will be printed in the inverse color of "
"the background."
)
in_block = fields.Boolean(
help='If checked, the data will be restrected in a '
'defined block on the label.')
block_width = fields.Integer(help='Width of the block.')
help="If checked, the data will be restrected in a "
"defined block on the label."
)
block_width = fields.Integer(help="Width of the block.")
block_lines = fields.Integer(
default=1, help='Maximum number of lines to print in the block.')
default=1, help="Maximum number of lines to print in the block."
)
block_spaces = fields.Integer(
help='Number of spaces added between lines in the block.')
help="Number of spaces added between lines in the block."
)
block_justify = fields.Selection(
selection=[
(zpl2.JUSTIFY_LEFT, 'Left'),
(zpl2.JUSTIFY_CENTER, 'Center'),
(zpl2.JUSTIFY_JUSTIFIED, 'Justified'),
(zpl2.JUSTIFY_RIGHT, 'Right'),
], string='Justify', required=True, default='L',
help='Choose how the text will be justified in the block.')
(zpl2.JUSTIFY_LEFT, "Left"),
(zpl2.JUSTIFY_CENTER, "Center"),
(zpl2.JUSTIFY_JUSTIFIED, "Justified"),
(zpl2.JUSTIFY_RIGHT, "Right"),
],
string="Justify",
required=True,
default="L",
help="Choose how the text will be justified in the block.",
)
block_left_margin = fields.Integer(
string='Left Margin',
help='Left margin for the second and other lines in the block.')
string="Left Margin",
help="Left margin for the second and other lines in the block.",
)
graphic_image = fields.Binary(
string='Image', attachment=True,
help='This field holds a static image to print. '
'If not set, the data field is evaluated.')
string="Image",
attachment=True,
help="This field holds a static image to print. "
"If not set, the data field is evaluated.",
)