diff --git a/printer_zpl2/README.rst b/printer_zpl2/README.rst index 7ae188d..da103cc 100644 --- a/printer_zpl2/README.rst +++ b/printer_zpl2/README.rst @@ -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 diff --git a/printer_zpl2/models/printing_label_zpl2.py b/printer_zpl2/models/printing_label_zpl2.py index dcbf3a4..9552d8d 100644 --- a/printer_zpl2/models/printing_label_zpl2.py +++ b/printer_zpl2/models/printing_label_zpl2.py @@ -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() diff --git a/printer_zpl2/tests/__init__.py b/printer_zpl2/tests/__init__.py index c01975e..cc4e18f 100644 --- a/printer_zpl2/tests/__init__.py +++ b/printer_zpl2/tests/__init__.py @@ -3,3 +3,4 @@ from . import test_printing_label_zpl2 from . import test_wizard_print_record_label +from . import test_generate_action diff --git a/printer_zpl2/tests/test_generate_action.py b/printer_zpl2/tests/test_generate_action.py new file mode 100644 index 0000000..194dd87 --- /dev/null +++ b/printer_zpl2/tests/test_generate_action.py @@ -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) diff --git a/printer_zpl2/views/printing_label_zpl2.xml b/printer_zpl2/views/printing_label_zpl2.xml index aad0e9f..fd7d04c 100644 --- a/printer_zpl2/views/printing_label_zpl2.xml +++ b/printer_zpl2/views/printing_label_zpl2.xml @@ -19,6 +19,9 @@