From a33df072d86a4f019c387811596f5f8b0a01bb70 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 24 Aug 2023 11:32:48 +0200 Subject: [PATCH] [IMP] mrp: auto-print MO reception report Add in feature to auto-print reception (allocation) report when the MO is done. Note that only MOs with an allocation will be printed otherwise the form will only have the MO name/barcode and nothing else in it (i.e. not very useful). Part of task: 3046178 - general auto-print goal closes odoo/odoo#126791 Related: odoo/enterprise#43362 Related: odoo/upgrade#5298 Signed-off-by: Arnold Moyaux (arm) --- addons/mrp/models/mrp_production.py | 10 ++++++++++ addons/mrp/models/stock_picking.py | 3 +++ addons/mrp/views/stock_picking_views.xml | 1 + 3 files changed, 14 insertions(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index eb4bdcf4964..f616ccf03cf 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -2640,6 +2640,16 @@ class MrpProduction(models.Model): clean_action(action, self.env) report_actions.append(action) if self.user_has_groups('mrp.group_mrp_reception_report'): + reception_reports_to_print = self.filtered( + lambda p: p.picking_type_id.auto_print_mrp_reception_report + and p.picking_type_id.code == 'mrp_operation' + and p.move_finished_ids.move_dest_ids + ) + if reception_reports_to_print: + action = self.env.ref('stock.stock_reception_report_action').report_action(reception_reports_to_print, config=False) + action['context'] = dict({'default_production_ids': reception_reports_to_print.ids}, **self.env.context) + clean_action(action, self.env) + report_actions.append(action) reception_labels_to_print = self.filtered(lambda p: p.picking_type_id.auto_print_mrp_reception_report_labels and p.picking_type_id.code == 'mrp_operation') if reception_labels_to_print: moves_to_print = reception_labels_to_print.move_finished_ids.move_dest_ids diff --git a/addons/mrp/models/stock_picking.py b/addons/mrp/models/stock_picking.py index 16329a3b57d..828e484b04c 100644 --- a/addons/mrp/models/stock_picking.py +++ b/addons/mrp/models/stock_picking.py @@ -41,6 +41,9 @@ class StockPickingType(models.Model): done_mrp_lot_label_to_print = fields.Selection( [('pdf', 'PDF'), ('zpl', 'ZPL')], "Lot/SN Label to Print", default='pdf') + auto_print_mrp_reception_report = fields.Boolean( + "Auto Print Allocation Report", + help="If this checkbox is ticked, Odoo will automatically print the allocation report of a MO when it is done and has assigned moves.") auto_print_mrp_reception_report_labels = fields.Boolean( "Auto Print Allocation Report Labels", help="If this checkbox is ticked, Odoo will automatically print the allocation report labels of a MO when it is done.") diff --git a/addons/mrp/views/stock_picking_views.xml b/addons/mrp/views/stock_picking_views.xml index b2eb8bc80ab..3985a8fe982 100644 --- a/addons/mrp/views/stock_picking_views.xml +++ b/addons/mrp/views/stock_picking_views.xml @@ -155,6 +155,7 @@