Added graphic image support

This commit is contained in:
Jos De Graeve
2017-11-02 10:04:25 +01:00
committed by mreficent
parent 10fc45ce3e
commit d77cd4858c
5 changed files with 36 additions and 3 deletions

View File

@@ -82,6 +82,7 @@ Contributors
------------ ------------
* Sylvain Garancher <sylvain.garancher@syleam.fr> * Sylvain Garancher <sylvain.garancher@syleam.fr>
* Jos De Graeve <Jos.DeGraeve@apertoso.be>
Maintainer Maintainer
---------- ----------

View File

@@ -6,7 +6,7 @@
'name': 'Printer ZPL II', 'name': 'Printer ZPL II',
'version': '10.0.1.1.1', 'version': '10.0.1.1.1',
'category': 'Printer', 'category': 'Printer',
'author': 'SYLEAM, Odoo Community Association (OCA)', 'author': 'SYLEAM, 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': {

View File

@@ -3,8 +3,11 @@
# 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 time import time
import base64
import datetime import datetime
import io
import logging import logging
from PIL import Image, ImageOps
from odoo import api, exceptions, fields, models from odoo import api, exceptions, fields, models
from odoo.tools.translate import _ from odoo.tools.translate import _
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
@@ -117,6 +120,29 @@ class PrintingLabelZpl2(models.Model):
zpl2.ARG_COLOR: component.color, zpl2.ARG_COLOR: component.color,
zpl2.ARG_ROUNDING: component.rounding, zpl2.ARG_ROUNDING: component.rounding,
}) })
elif component.component_type == 'graphic':
pil_image = Image.open(io.BytesIO(
base64.b64decode(component.graphic_image or data)))
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': elif component.component_type == 'circle':
label_data.graphic_circle( label_data.graphic_circle(
component_offset_x, component_offset_y, { component_offset_x, component_offset_y, {

View File

@@ -34,6 +34,7 @@ class PrintingLabelZpl2Component(models.Model):
('text', 'Text'), ('text', 'Text'),
('rectangle', 'Rectangle / Line'), ('rectangle', 'Rectangle / Line'),
('circle', 'Circle'), ('circle', 'Circle'),
('graphic', 'Graphic'),
(zpl2.BARCODE_CODE_11, 'Code 11'), (zpl2.BARCODE_CODE_11, 'Code 11'),
(zpl2.BARCODE_INTERLEAVED_2_OF_5, 'Interleaved 2 of 5'), (zpl2.BARCODE_INTERLEAVED_2_OF_5, 'Interleaved 2 of 5'),
(zpl2.BARCODE_CODE_39, 'Code 39'), (zpl2.BARCODE_CODE_39, 'Code 39'),
@@ -142,3 +143,7 @@ class PrintingLabelZpl2Component(models.Model):
block_left_margin = fields.Integer( block_left_margin = fields.Integer(
string='Left Margin', string='Left Margin',
help='Left margin for the second and other lines in the block.') 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.')

View File

@@ -52,6 +52,7 @@
</group> </group>
<group> <group>
<field name="data" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/> <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')]}"/> <field name="sublabel_id" attrs="{'invisible': [('component_type', '!=', 'sublabel')]}"/>
</group> </group>
</group> </group>
@@ -59,7 +60,7 @@
<page string="Format" attrs="{'invisible': [('component_type', '=', ('sublabel'))]}"> <page string="Format" attrs="{'invisible': [('component_type', '=', ('sublabel'))]}">
<group> <group>
<field name="height"/> <field name="height"/>
<field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle'))]}"/> <field name="width" attrs="{'invisible': [('component_type', 'not in', ('text', 'rectangle', 'circle', 'graphic'))]}"/>
<field name="reverse_print"/> <field name="reverse_print"/>
<field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/> <field name="orientation" attrs="{'invisible': [('component_type', 'in', ('rectangle', 'circle'))]}"/>
<field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/> <field name="font" attrs="{'invisible': [('component_type', '!=', 'text')]}"/>
@@ -69,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'))]}"> <page string="Barcode Format" attrs="{'invisible': [('component_type', 'in', ('text', 'rectangle', 'circle', 'sublabel','graphic'))]}">
<group> <group>
<field name="check_digits"/> <field name="check_digits"/>
<field name="interpretation_line"/> <field name="interpretation_line"/>