Added graphic image support

This commit is contained in:
Jos De Graeve
2017-11-02 10:04:25 +01:00
committed by Nils Hamerlinck
parent 4ff66113a9
commit 75c3ae6fd1
5 changed files with 36 additions and 3 deletions

View File

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

View File

@@ -6,7 +6,7 @@
'name': 'Printer ZPL II',
'version': '10.0.1.1.1',
'category': 'Printer',
'author': 'SYLEAM, Odoo Community Association (OCA)',
'author': 'SYLEAM, Apertoso NV, Odoo Community Association (OCA)',
'website': 'http://www.syleam.fr/',
'license': 'AGPL-3',
'external_dependencies': {

View File

@@ -3,8 +3,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
import base64
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.tools.safe_eval import safe_eval
@@ -117,6 +120,29 @@ class PrintingLabelZpl2(models.Model):
zpl2.ARG_COLOR: component.color,
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':
label_data.graphic_circle(
component_offset_x, component_offset_y, {

View File

@@ -34,6 +34,7 @@ class PrintingLabelZpl2Component(models.Model):
('text', 'Text'),
('rectangle', 'Rectangle / 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'),
@@ -142,3 +143,7 @@ class PrintingLabelZpl2Component(models.Model):
block_left_margin = fields.Integer(
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.')

View File

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