[IMP] Add a button to generate an action to launch the print wizard

This commit is contained in:
Florent de Labarre
2018-01-23 00:25:39 +01:00
committed by Lois Rilo
parent 041ee4cd82
commit 1024ddfa42
5 changed files with 61 additions and 1 deletions

View File

@@ -59,7 +59,6 @@ You can also use the generic label printing wizard, if added on some models.
Known issues / Roadmap
======================
* Add a button to generate the ir.values for a model
* Develop a "Designer" view in a separate module, to allow drawing labels with simple mouse clicks/drags
Bug Tracker

View File

@@ -46,6 +46,8 @@ class PrintingLabelZpl2(models.Model):
string="Restore printer's configuration",
help="Restore printer's saved configuration and end of each label ",
default=True)
action_window_id = fields.Many2one(
comodel_name='ir.actions.act_window', string='Action', readonly=True)
def _generate_zpl2_components_data(
self, label_data, record, page_number=1, page_count=1,
@@ -226,3 +228,20 @@ class PrintingLabelZpl2(models.Model):
report=None, content=label_contents, doc_format='raw')
return True
def create_action(self):
for label in self.filtered(lambda record: not record.action_window_id):
label.action_window_id = self.env['ir.actions.act_window'].create({
'name': _('Print Label'),
'src_model': label.model_id.model,
'binding_model_id': label.model_id.id,
'res_model': 'wizard.print.record.label',
'view_mode': 'form',
'target': 'new',
'binding_type': 'action',
})
return True
def unlink_action(self):
self.mapped('action_window_id').unlink()

View File

@@ -3,3 +3,4 @@
from . import test_printing_label_zpl2
from . import test_wizard_print_record_label
from . import test_generate_action

View File

@@ -0,0 +1,38 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
model = 'odoo.addons.base_report_to_printer.models.printing_server'
class TestWizardPrintRecordLabel(TransactionCase):
def setUp(self):
super(TestWizardPrintRecordLabel, self).setUp()
self.Model = self.env['wizard.print.record.label']
self.server = self.env['printing.server'].create({})
self.printer = self.env['printing.printer'].create({
'name': 'Printer',
'server_id': self.server.id,
'system_name': 'Sys Name',
'default': True,
'status': 'unknown',
'status_message': 'Msg',
'model': 'res.users',
'location': 'Location',
'uri': 'URI',
})
self.label = self.env['printing.label.zpl2'].create({
'name': 'ZPL II Label',
'model_id': self.env.ref(
'base_report_to_printer.model_printing_printer').id,
})
def test_create_action(self):
""" Check the creation of action """
self.label.create_action()
self.assertTrue(self.label.action_window_id)
def test_unlink_action(self):
""" Check the unlink of action """
self.label.unlink_action()
self.assertFalse(self.label.action_window_id)

View File

@@ -19,6 +19,9 @@
<form string="ZPL II Label">
<sheet>
<div class="oe_button_box" name="button_box">
<field name="action_window_id" invisible="1"/>
<button name="create_action" string="Add in the 'Action' menu" type="object" attrs="{'invisible':[('action_window_id','!=',False)]}" icon="fa-plus-square" help="Display an option on related documents." class="oe_stat_button"/>
<button name="unlink_action" string="Remove from the 'Action' menu" type="object" attrs="{'invisible':[('action_window_id','=',False)]}" icon="fa-minus-square" help="Remove the contextual action." class="oe_stat_button"/>
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button" options="{&quot;terminology&quot;: &quot;archive&quot;}"/>
</button>