mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] Add a test mode to print a label on write
This commit is contained in:
committed by
Lois Rilo
parent
2318cc670e
commit
2f9de1f5f6
@@ -25,6 +25,7 @@ To configure this module, you need to:
|
|||||||
#. Go to *Settings > Printing > Labels > ZPL II*
|
#. Go to *Settings > Printing > Labels > ZPL II*
|
||||||
#. Create new labels
|
#. Create new labels
|
||||||
#. Import ZPL2 code
|
#. Import ZPL2 code
|
||||||
|
#. 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 :
|
||||||
|
|||||||
@@ -49,9 +49,12 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
default=True)
|
default=True)
|
||||||
action_window_id = fields.Many2one(
|
action_window_id = fields.Many2one(
|
||||||
comodel_name='ir.actions.act_window', string='Action', readonly=True)
|
comodel_name='ir.actions.act_window', string='Action', readonly=True)
|
||||||
|
test_print_mode = fields.Boolean(string='Mode Print')
|
||||||
test_labelary_mode = fields.Boolean(string='Mode Labelary')
|
test_labelary_mode = fields.Boolean(string='Mode Labelary')
|
||||||
record_id = fields.Integer(string='Record ID', default=1)
|
record_id = fields.Integer(string='Record ID', default=1)
|
||||||
extra = fields.Text(string="Extra", default='{}')
|
extra = fields.Text(string="Extra", default='{}')
|
||||||
|
printer_id = fields.Many2one(
|
||||||
|
comodel_name='printing.printer', string='Printer')
|
||||||
labelary_image = fields.Binary(string='Image from Labelary', readonly=True)
|
labelary_image = fields.Binary(string='Image from Labelary', readonly=True)
|
||||||
labelary_dpmm = fields.Selection(
|
labelary_dpmm = fields.Selection(
|
||||||
selection=[
|
selection=[
|
||||||
@@ -293,6 +296,14 @@ class PrintingLabelZpl2(models.Model):
|
|||||||
|
|
||||||
return record
|
return record
|
||||||
|
|
||||||
|
def print_test_label(self):
|
||||||
|
for label in self:
|
||||||
|
if label.test_print_mode and label.record_id and label.printer_id:
|
||||||
|
record = label._get_record()
|
||||||
|
extra = safe_eval(label.extra, {'env': self.env})
|
||||||
|
if record:
|
||||||
|
label.print_label(label.printer_id, record, **extra)
|
||||||
|
|
||||||
@api.onchange(
|
@api.onchange(
|
||||||
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
|
'record_id', 'labelary_dpmm', 'labelary_width', 'labelary_height',
|
||||||
'component_ids', 'origin_x', 'origin_y')
|
'component_ids', 'origin_x', 'origin_y')
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# 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
|
||||||
|
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
@@ -38,6 +39,15 @@ class TestWizardPrintRecordLabel(TransactionCase):
|
|||||||
record = Obj.search([], limit=1, order='id desc')
|
record = Obj.search([], limit=1, order='id desc')
|
||||||
self.assertEqual(res, record)
|
self.assertEqual(res, record)
|
||||||
|
|
||||||
|
@mock.patch('%s.cups' % model)
|
||||||
|
def test_print_label_test(self, cups):
|
||||||
|
""" Check if print test """
|
||||||
|
self.label.test_print_mode = True
|
||||||
|
self.label.printer_id = self.printer
|
||||||
|
self.label.record_id = 10
|
||||||
|
self.label.print_test_label()
|
||||||
|
cups.Connection().printFile.assert_called_once()
|
||||||
|
|
||||||
def test_emulation_without_params(self):
|
def test_emulation_without_params(self):
|
||||||
""" Check if not execute next if not in this mode """
|
""" Check if not execute next if not in this mode """
|
||||||
self.label.test_labelary_mode = False
|
self.label.test_labelary_mode = False
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
<field name="origin_y"/>
|
<field name="origin_y"/>
|
||||||
<field name="restore_saved_config"/>
|
<field name="restore_saved_config"/>
|
||||||
</group>
|
</group>
|
||||||
|
<group attrs="{'invisible':[('test_print_mode', '=', False)]}">
|
||||||
|
<button name="print_test_label" string="Print Test" type="object" class="oe_highlight"/>
|
||||||
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="Composents">
|
<page string="Composents">
|
||||||
<field name="component_ids" nolabel="1" colspan="4">
|
<field name="component_ids" nolabel="1" colspan="4">
|
||||||
@@ -139,19 +142,21 @@
|
|||||||
<page string="Test Mode">
|
<page string="Test Mode">
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
|
<field name="test_print_mode"/>
|
||||||
<field name="test_labelary_mode"/>
|
<field name="test_labelary_mode"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
<field name="record_id" context="{'select_model_id':model_id}" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
<field name="record_id" attrs="{'invisible':[('test_print_mode', '=', False), ('test_labelary_mode', '=', False)], 'required':['|', ('test_print_mode', '=', True), ('test_labelary_mode', '=', True)]}"/>
|
||||||
|
<field name="printer_id" attrs="{'invisible':[('test_print_mode', '=', False)], 'required':[('test_print_mode', '=', True)]}"/>
|
||||||
<field name="labelary_dpmm" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
<field name="labelary_dpmm" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
||||||
<field name="labelary_width" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
<field name="labelary_width" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
||||||
<field name="labelary_height" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
<field name="labelary_height" attrs="{'invisible':[('test_labelary_mode', '=', False)], 'required':[('test_labelary_mode', '=', True)]}"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group string="Extra">
|
<group string="Extra">
|
||||||
<field name="extra" nolabel="1" widget="ace" options="{'mode': 'python'}" attrs="{'invisible':[('test_labelary_mode', '=', False)]}"/>
|
<field name="extra" nolabel="1" widget="ace" options="{'mode': 'python'}" attrs="{'invisible':[('test_print_mode', '=', False), ('test_labelary_mode', '=', False)]}"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
|
|||||||
Reference in New Issue
Block a user