[MIG][11.0] printer_zpl2

This commit is contained in:
Florent de Labarre
2018-01-23 01:24:26 +01:00
committed by mreficent
parent 88561fe7c8
commit 9a8b2e7af9
13 changed files with 150 additions and 149 deletions

View File

@@ -25,18 +25,18 @@ To configure this module, you need to:
#. Go to *Settings > Printing > Labels > ZPL II*
#. Create new labels
It's also possible to add a label printing wizard on any model by creating a new *ir.values* record.
It's also possible to add a label printing wizard on any model by creating a new *ir.actions.act_window* record.
For example, to add the printing wizard on the *product.product* model :
.. code-block:: xml
<record model="ir.values" id="wizard_wizard_print_product_label">
<field name="name">Print Product Label</field>
<field name="key">action</field>
<field name="key2">client_action_multi</field>
<field name="model">product.product</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('printer_zpl2.action_wizard_print_record_label_view'))"/>
</record>
<act_window id="action_wizard_purchase"
name="Print Label"
src_model="product.product"
res_model="wizard.print.record.label"
view_mode="form"
target="new"
key2="client_action_multi"/>
Usage
=====
@@ -54,7 +54,7 @@ You can also use the generic label printing wizard, if added on some models.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/144/10.0
:target: https://runbot.odoo-community.org/runbot/144/11.0
Known issues / Roadmap
======================
@@ -82,6 +82,7 @@ Contributors
------------
* Sylvain Garancher <sylvain.garancher@syleam.fr>
* Florent de Labarre
* Jos De Graeve <Jos.DeGraeve@apertoso.be>
Maintainer

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Printer ZPL II',
'version': '10.0.1.1.1',
'version': '11.0.1.0.0',
'category': 'Printer',
'author': 'SYLEAM, Apertoso NV, Odoo Community Association (OCA)',
'website': 'http://www.syleam.fr/',

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -8,8 +7,7 @@ import datetime
import io
import logging
from PIL import Image, ImageOps
from odoo import api, exceptions, fields, models
from odoo.tools.translate import _
from odoo import exceptions, fields, models, _
from odoo.tools.safe_eval import safe_eval
_logger = logging.getLogger(__name__)
@@ -23,8 +21,10 @@ except ImportError:
class PrintingLabelZpl2(models.Model):
_name = 'printing.label.zpl2'
_description = 'ZPL II Label'
_order = 'model_id, name, id'
name = fields.Char(required=True, help='Label Name.')
active = fields.Boolean(default=True)
description = fields.Char(help='Long description for this label.')
model_id = fields.Many2one(
comodel_name='ir.model', string='Model', required=True,
@@ -47,7 +47,6 @@ class PrintingLabelZpl2(models.Model):
help="Restore printer's saved configuration and end of each label ",
default=True)
@api.multi
def _generate_zpl2_components_data(
self, label_data, record, page_number=1, page_count=1,
label_offset_x=0, label_offset_y=0, **extra):
@@ -123,7 +122,7 @@ class PrintingLabelZpl2(models.Model):
elif component.component_type == 'graphic':
image = component.graphic_image or data
pil_image = Image.open(io.BytesIO(
base64.b64decode(image)))
base64.b64decode(image))).convert('RGB')
if component.width and component.height:
pil_image = pil_image.resize(
(component.width, component.height))
@@ -188,7 +187,6 @@ class PrintingLabelZpl2(models.Model):
component.origin_y + offset_y,
component.component_type, barcode_arguments, data)
@api.multi
def _generate_zpl2_data(self, record, page_count=1, **extra):
self.ensure_one()
label_data = zpl2.Zpl2()
@@ -212,7 +210,6 @@ class PrintingLabelZpl2(models.Model):
return label_data.output()
@api.multi
def print_label(self, printer, record, page_count=1, **extra):
for label in self:
if record._name != label.model_id.model:
@@ -223,6 +220,7 @@ class PrintingLabelZpl2(models.Model):
# Send the label to printer
label_contents = label._generate_zpl2_data(
record, page_count=page_count, **extra)
printer.print_document(None, label_contents, 'raw')
printer.print_document(
report=None, content=label_contents, doc_format='raw')
return True

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -16,7 +15,7 @@ except ImportError:
class PrintingLabelZpl2Component(models.Model):
_name = 'printing.label.zpl2.component'
_description = 'ZPL II Label Component'
_order = 'sequence'
_order = 'sequence, id'
label_id = fields.Many2one(
comodel_name='printing.label.zpl2', string='Label',

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -72,7 +71,7 @@ class TestPrintingLabelZpl2(TransactionCase):
def test_empty_label_contents(self):
""" Check contents of an empty label """
label = self.new_label()
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode('utf-8')
self.assertEqual(
contents,
# Label start
@@ -105,7 +104,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'sublabel',
'sublabel_id': sublabel.id,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode('utf-8')
self.assertEqual(
contents,
# Label start
@@ -150,7 +149,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'repeat_count': 3,
'repeat_offset_y': 15,
})
contents = label._generate_zpl2_data(label)
contents = label._generate_zpl2_data(label).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -210,7 +209,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'repeat_count': 3,
'repeat_offset_y': 15,
})
contents = label._generate_zpl2_data(label)
contents = label._generate_zpl2_data(label).decode('utf-8')
self.assertEqual(
contents,
# Label start
@@ -262,7 +261,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'repeat_count': 3,
'repeat_offset_y': 15,
})
contents = label._generate_zpl2_data(label)
contents = label._generate_zpl2_data(label).decode('utf-8')
self.assertEqual(
contents,
# Label start
@@ -341,7 +340,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'repeat_count': 3,
'repeat_offset_y': 15,
})
contents = label._generate_zpl2_data(label)
contents = label._generate_zpl2_data(label).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -403,9 +402,9 @@ class TestPrintingLabelZpl2(TransactionCase):
data = 'Some text'
self.new_component({
'label_id': label.id,
'data': '"' + data + '"',
'data': '"%s"' % data,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -438,7 +437,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'data': '"' + data + '"',
'reverse_print': True,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -473,7 +472,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'data': '"' + data + '"',
'in_block': True,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -506,7 +505,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'label_id': label.id,
'component_type': 'rectangle',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -535,7 +534,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'label_id': label.id,
'component_type': 'circle',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -566,7 +565,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'code_11',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -601,7 +600,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'interleaved_2_of_5',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -636,7 +635,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'code_39',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -671,7 +670,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'code_49',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -707,7 +706,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'data': '"' + data + '"',
'interpretation_line': True,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -746,7 +745,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'interpretation_line': True,
'interpretation_line_above': True,
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -781,7 +780,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'pdf417',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -816,7 +815,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'ean-8',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -851,7 +850,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'upc-e',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -886,7 +885,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'code_128',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -921,7 +920,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'ean-13',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start
@@ -956,7 +955,7 @@ class TestPrintingLabelZpl2(TransactionCase):
'component_type': 'qr_code',
'data': '"' + data + '"',
})
contents = label._generate_zpl2_data(self.printer)
contents = label._generate_zpl2_data(self.printer).decode("utf-8")
self.assertEqual(
contents,
# Label start

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

View File

@@ -5,7 +5,6 @@
-->
<odoo>
<record id="view_printing_label_zpl2_tree" model="ir.ui.view">
<field name="name">printing.label.zpl2.tree</field>
<field name="model">printing.label.zpl2</field>
<field name="arch" type="xml">
<tree string="ZPL II Label">
@@ -15,115 +14,125 @@
</field>
</record>
<record id="view_printing_label_zpl2_form" model="ir.ui.view">
<field name="name">printing.label.zpl2.form</field>
<field name="model">printing.label.zpl2</field>
<field name="arch" type="xml">
<form string="ZPL II Label">
<group col="4">
<field name="name"/>
<field name="model_id"/>
<field name="description"/>
<field name="width"/>
<field name="origin_x"/>
<field name="origin_y"/>
<field name="restore_saved_config"/>
</group>
<field name="component_ids" nolabel="1" colspan="4">
<tree string="Label Component">
<field name="sequence"/>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button" options="{&quot;terminology&quot;: &quot;archive&quot;}"/>
</button>
</div>
<group col="4">
<field name="name"/>
<field name="component_type"/>
<field name="model_id"/>
<field name="description"/>
<field name="width"/>
<field name="origin_x"/>
<field name="origin_y"/>
</tree>
<form string="Label Component">
<group>
<group>
<field name="name"/>
<field name="sequence"/>
</group>
<group>
<field name="component_type"/>
<field name="repeat"/>
</group>
<group>
<field name="origin_x"/>
<field name="origin_y"/>
</group>
<group>
<field name="data" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="graphic_image" attrs="{'invisible': [('component_type', '!=', 'graphic')]}"/>
<field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/>
</group>
</group>
<notebook colspan="4">
<page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code'))]}">
<group>
<field name="height"/>
<field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/>
<field name="reverse_print"/>
<field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="in_block" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="thickness" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/>
<field name="color" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/>
</group>
</page>
<!-- Barcode specific arguments -->
<page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code'))]}">
<group>
<field name="check_digits"/>
<field name="interpretation_line"/>
<field name="interpretation_line_above"/>
<field name="module_width"/>
<field name="bar_width_ratio"/>
<field name="security_level"/>
<field name="columns_count"/>
<field name="rows_count"/>
<field name="truncate"/>
</group>
</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 -->
<page string="Text Block Format" attrs="{'invisible': ['|', ('component_type', '!=', 'text'), ('in_block', '=', False)]}">
<group>
<field name="block_width"/>
<field name="block_lines"/>
<field name="block_spaces"/>
<field name="block_justify"/>
<field name="block_left_margin"/>
</group>
</page>
<!-- Repeat specific arguments -->
<page string="Repeat" attrs="{'invisible': [('repeat', '=', False)]}">
<group>
<field name="repeat_offset"/>
<field name="repeat_count"/>
<field name="repeat_offset_x"/>
<field name="repeat_offset_y"/>
</group>
</page>
</notebook>
</form>
</field>
<field name="restore_saved_config"/>
</group>
<notebook>
<page string="Composents">
<field name="component_ids" nolabel="1" colspan="4">
<tree string="Label Component">
<field name="sequence"/>
<field name="name"/>
<field name="component_type"/>
<field name="origin_x"/>
<field name="origin_y"/>
</tree>
<form string="Label Component">
<group>
<group>
<field name="name"/>
<field name="sequence"/>
</group>
<group>
<field name="component_type"/>
<field name="repeat"/>
</group>
<group>
<field name="origin_x"/>
<field name="origin_y"/>
</group>
<group>
<field name="data" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="graphic_image" attrs="{'invisible': [('component_type', '!=', 'graphic')]}"/>
<field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/>
</group>
</group>
<notebook colspan="4">
<page string="Format" attrs="{'invisible': [('component_type', 'in', ('sublabel', 'qr_code'))]}">
<group>
<field name="height"/>
<field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/>
<field name="reverse_print"/>
<field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="in_block" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
<field name="thickness" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/>
<field name="color" attrs="{'invisible': [('component_type', 'not in', ('rectangle', 'circle'))]}"/>
</group>
</page>
<!-- Barcode specific arguments -->
<page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel', 'graphic', 'qr_code'))]}">
<group>
<field name="check_digits"/>
<field name="interpretation_line"/>
<field name="interpretation_line_above"/>
<field name="module_width"/>
<field name="bar_width_ratio"/>
<field name="security_level"/>
<field name="columns_count"/>
<field name="rows_count"/>
<field name="truncate"/>
</group>
</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 -->
<page string="Text Block Format" attrs="{'invisible': ['|', ('component_type', '!=', 'text'), ('in_block', '=', False)]}">
<group>
<field name="block_width"/>
<field name="block_lines"/>
<field name="block_spaces"/>
<field name="block_justify"/>
<field name="block_left_margin"/>
</group>
</page>
<!-- Repeat specific arguments -->
<page string="Repeat" attrs="{'invisible': [('repeat', '=', False)]}">
<group>
<field name="repeat_offset"/>
<field name="repeat_count"/>
<field name="repeat_offset_x"/>
<field name="repeat_offset_y"/>
</group>
</page>
</notebook>
</form>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="view_printing_label_zpl2_search" model="ir.ui.view">
<field name="name">printing.label.zpl2.search</field>
<field name="model">printing.label.zpl2</field>
<field name="arch" type="xml">
<search string="ZPL II Label">
<field name="name"/>
<field name="model_id"/>
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -38,7 +37,6 @@ class PrintRecordLabel(models.TransientModel):
return values
@api.multi
def print_label(self):
""" Prints a label per selected record """
record_model = self.env.context['active_model']

View File

@@ -13,7 +13,10 @@
<field name="printer_id"/>
<field name="label_id"/>
</group>
<button string="Print Label" type="object" name="print_label"/>
<footer>
<button type="special" special="cancel" string="Cancel"/>
<button string="Print label" type="object" name="print_label" class="oe_highlight"/>
</footer>
</form>
</field>
</record>