mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
Added graphic image support
This commit is contained in:
@@ -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
|
||||||
----------
|
----------
|
||||||
|
|||||||
@@ -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': {
|
||||||
|
|||||||
@@ -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, {
|
||||||
|
|||||||
@@ -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.')
|
||||||
|
|||||||
@@ -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"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user