mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[MIG] printer_zpl2: Migration to 12.0
This commit is contained in:
committed by
Lois Rilo
parent
a862116674
commit
3ef9604675
@@ -28,9 +28,7 @@ To configure this module, you need to:
|
|||||||
#. Use the Test Mode tab during the creation
|
#. Use the Test Mode tab during the creation
|
||||||
|
|
||||||
It's also possible to add a label printing wizard on any model by creating a new *ir.actions.act_window* 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 :
|
For example, to add the printing wizard on the *product.product* model ::
|
||||||
|
|
||||||
.. code-block:: xml
|
|
||||||
|
|
||||||
<act_window id="action_wizard_purchase"
|
<act_window id="action_wizard_purchase"
|
||||||
name="Print Label"
|
name="Print Label"
|
||||||
@@ -45,9 +43,8 @@ Usage
|
|||||||
|
|
||||||
To print a label, you need to call use the label printing method from anywhere (other modules, server actions, etc.).
|
To print a label, you need to call use the label printing method from anywhere (other modules, server actions, etc.).
|
||||||
|
|
||||||
.. code-block:: python
|
Example : Print the label of a product ::
|
||||||
|
|
||||||
# Example : Print the label of a product
|
|
||||||
self.env['printing.label.zpl2'].browse(label_id).print_label(
|
self.env['printing.label.zpl2'].browse(label_id).print_label(
|
||||||
self.env['printing.printer'].browse(printer_id),
|
self.env['printing.printer'].browse(printer_id),
|
||||||
self.env['product.product'].browse(product_id))
|
self.env['product.product'].browse(product_id))
|
||||||
@@ -56,7 +53,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
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/144/11.0
|
:target: https://runbot.odoo-community.org/runbot/144/12.0
|
||||||
|
|
||||||
Known issues / Roadmap
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
|
# Copyright (C) 2016 SUBTENO-IT (<https://subteno-it.fr>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
|
# Copyright (C) 2016 SUBTENO-IT (<https://subteno-it.fr>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Printer ZPL II',
|
'name': 'Printer ZPL II',
|
||||||
'version': '11.0.1.0.0',
|
'version': '12.0.1.0.0',
|
||||||
'category': 'Printer',
|
'category': 'Printer',
|
||||||
'author': 'SYLEAM, Apertoso NV, Odoo Community Association (OCA)',
|
'author': 'SUBTENO-IT, FLorent de Labarre, '
|
||||||
|
'Apertoso NV, Odoo Community Association (OCA)',
|
||||||
'website': 'http://www.syleam.fr/',
|
'website': 'http://www.syleam.fr/',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'external_dependencies': {
|
'external_dependencies': {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
component_ids = fields.One2many(
|
component_ids = fields.One2many(
|
||||||
comodel_name='printing.label.zpl2.component', inverse_name='label_id',
|
comodel_name='printing.label.zpl2.component', inverse_name='label_id',
|
||||||
string='Label Components',
|
string='Label Components',
|
||||||
help='Components which will be printed on the label.')
|
help='Components which will be printed on the label.', copy=True)
|
||||||
restore_saved_config = fields.Boolean(
|
restore_saved_config = fields.Boolean(
|
||||||
string="Restore printer's configuration",
|
string="Restore printer's configuration",
|
||||||
help="Restore printer's saved configuration and end of each label ",
|
help="Restore printer's saved configuration and end of each label ",
|
||||||
@@ -85,6 +85,9 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
})
|
})
|
||||||
data = safe_eval(component.data, eval_args) or ''
|
data = safe_eval(component.data, eval_args) or ''
|
||||||
|
|
||||||
|
if data == 'component_not_show':
|
||||||
|
continue
|
||||||
|
|
||||||
# Generate a list of elements if the component is repeatable
|
# Generate a list of elements if the component is repeatable
|
||||||
for idx in range(
|
for idx in range(
|
||||||
component.repeat_offset,
|
component.repeat_offset,
|
||||||
@@ -151,9 +154,14 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
component.diagonal_orientation,
|
component.diagonal_orientation,
|
||||||
})
|
})
|
||||||
elif component.component_type == 'graphic':
|
elif component.component_type == 'graphic':
|
||||||
image = component.graphic_image or data
|
# 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(
|
pil_image = Image.open(io.BytesIO(
|
||||||
base64.b64decode(image))).convert('RGB')
|
base64.b64decode(image))).convert('RGB')
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
if component.width and component.height:
|
if component.width and component.height:
|
||||||
pil_image = pil_image.resize(
|
pil_image = pil_image.resize(
|
||||||
(component.width, component.height))
|
(component.width, component.height))
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ DEFAULT_PYTHON_CODE = """# Python One-Liners
|
|||||||
# - page_number: Current Page
|
# - page_number: Current Page
|
||||||
# - page_count: Total Page
|
# - page_count: Total Page
|
||||||
# - time, datetime: Python libraries
|
# - time, datetime: Python libraries
|
||||||
|
# - return 'component_not_show' to don't show this component
|
||||||
# Exemple : object.name
|
# Exemple : object.name
|
||||||
|
|
||||||
|
|
||||||
""
|
""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2018 Florent Mirieu (<https://github.com/fmdl>)
|
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|||||||
@@ -1116,3 +1116,22 @@ class TestPrintingLabelZpl2(TransactionCase):
|
|||||||
'^FO50,50^GB100,100,100^FS\n'
|
'^FO50,50^GB100,100,100^FS\n'
|
||||||
'^JUR\n'
|
'^JUR\n'
|
||||||
'^XZ')
|
'^XZ')
|
||||||
|
|
||||||
|
def test_zpl2_component_not_show(self):
|
||||||
|
""" Check to don't show no things """
|
||||||
|
label = self.new_label()
|
||||||
|
data = 'component_not_show'
|
||||||
|
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'
|
||||||
|
'^JUR\n'
|
||||||
|
'^XZ')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2018 Florent Mirieu (<https://github.com/fmdl>)
|
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2018 Florent Mirieu (<https://github.com/fmdl>)
|
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<!--
|
<!--
|
||||||
Copyright 2016 SYLEAM
|
Copyright 2016 SUBTENO-IT
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
-->
|
-->
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2018 Florent Mirieu (<https://github.com/fmdl>)
|
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -376,13 +376,12 @@ class WizardImportZPl2(models.TransientModel):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def import_zpl2(self):
|
def import_zpl2(self):
|
||||||
|
self.ensure_one()
|
||||||
Zpl2Component = self.env['printing.label.zpl2.component']
|
Zpl2Component = self.env['printing.label.zpl2.component']
|
||||||
|
|
||||||
if self.delete_component:
|
if self.delete_component:
|
||||||
self.mapped('label_id.component_ids').unlink()
|
self.mapped('label_id.component_ids').unlink()
|
||||||
|
|
||||||
Model = self.env['printing.label.zpl2.component']
|
|
||||||
self.model_fields = Model.fields_get()
|
|
||||||
sequence = self._start_sequence()
|
sequence = self._start_sequence()
|
||||||
default = {}
|
default = {}
|
||||||
|
|
||||||
@@ -423,10 +422,12 @@ class WizardImportZPl2(models.TransientModel):
|
|||||||
vals['orientation'] = 'N'
|
vals['orientation'] = 'N'
|
||||||
|
|
||||||
# Field
|
# Field
|
||||||
|
Zpl2Component = self.env['printing.label.zpl2.component']
|
||||||
|
model_fields = Zpl2Component.fields_get()
|
||||||
component = {}
|
component = {}
|
||||||
for field, value in vals.items():
|
for field, value in vals.items():
|
||||||
if field in self.model_fields.keys():
|
if field in model_fields.keys():
|
||||||
field_type = self.model_fields[field].get('type', False)
|
field_type = model_fields[field].get('type', False)
|
||||||
if field_type == 'boolean':
|
if field_type == 'boolean':
|
||||||
if not value or value == zpl2.BOOL_NO:
|
if not value or value == zpl2.BOOL_NO:
|
||||||
value = False
|
value = False
|
||||||
|
|||||||
Reference in New Issue
Block a user