From 2491024284c0fc710d5b9242ba1d0d4084950247 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Mon, 24 Apr 2023 12:05:05 +0200 Subject: [PATCH] [IMP] mrp: auto-print MO product labels Add in feature to allow auto-printing of product labels when MO is done. Part of task: 3046178 - MRP behavior auto-printing Part-of: odoo/odoo#126791 --- addons/mrp/models/mrp_production.py | 12 ++++++++++++ addons/mrp/models/stock_picking.py | 6 ++++++ addons/mrp/views/stock_picking_views.xml | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index fbaf86bd9a8..eaa7a842cb5 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -2625,4 +2625,16 @@ class MrpProduction(models.Model): action = self.env.ref("mrp.action_report_production_order").report_action(productions_to_print.ids, config=False) clean_action(action, self.env) report_actions.append(action) + productions_to_print = self.filtered(lambda p: p.picking_type_id.auto_print_done_mrp_product_labels) + productions_by_print_formats = productions_to_print.grouped(lambda p: p.picking_type_id.mrp_product_label_to_print) + for print_format in productions_to_print.picking_type_id.mapped('mrp_product_label_to_print'): + labels_to_print = productions_by_print_formats.get(print_format) + if print_format == 'pdf': + action = self.env.ref("mrp.action_report_finished_product").report_action(labels_to_print.ids, config=False) + clean_action(action, self.env) + report_actions.append(action) + elif print_format == 'zpl': + action = self.env.ref("mrp.label_manufacture_template").report_action(labels_to_print.ids, config=False) + clean_action(action, self.env) + report_actions.append(action) return report_actions diff --git a/addons/mrp/models/stock_picking.py b/addons/mrp/models/stock_picking.py index f53dacb1897..614f0472691 100644 --- a/addons/mrp/models/stock_picking.py +++ b/addons/mrp/models/stock_picking.py @@ -29,6 +29,12 @@ class StockPickingType(models.Model): auto_print_done_production_order = fields.Boolean( "Auto Print Done Production Order", help="If this checkbox is ticked, Odoo will automatically print the production order of a MO when it is done.") + auto_print_done_mrp_product_labels = fields.Boolean( + "Auto Print Produced Product Labels", + help="If this checkbox is ticked, Odoo will automatically print the product labels of a MO when it is done.") + mrp_product_label_to_print = fields.Selection( + [('pdf', 'PDF'), ('zpl', 'ZPL')], + "Product Label to Print", default='pdf') @api.depends('code') def _compute_use_create_lots(self): diff --git a/addons/mrp/views/stock_picking_views.xml b/addons/mrp/views/stock_picking_views.xml index 32686e49264..ff89af6ab48 100644 --- a/addons/mrp/views/stock_picking_views.xml +++ b/addons/mrp/views/stock_picking_views.xml @@ -143,6 +143,12 @@ +