diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index dd72d9d40a4..fbaf86bd9a8 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -11,6 +11,7 @@ from collections import defaultdict from dateutil.relativedelta import relativedelta from odoo import api, fields, models, _, Command +from odoo.addons.web.controllers.utils import clean_action from odoo.exceptions import UserError, ValidationError from odoo.tools import float_compare, float_round, float_is_zero, format_datetime from odoo.tools.misc import OrderedSet, format_date, groupby as tools_groupby @@ -1967,48 +1968,78 @@ class MrpProduction(models.Model): 'state': 'done', }) + report_actions = self._get_autoprint_done_report_actions() if self.env.context.get('skip_redirection'): + if report_actions: + return { + 'type': 'ir.actions.client', + 'tag': 'do_multi_print', + 'params': { + 'reports': report_actions, + } + } return True - + another_action = False if not backorders: if self.env.context.get('from_workorder'): - return { + another_action = { 'type': 'ir.actions.act_window', 'res_model': 'mrp.production', 'views': [[self.env.ref('mrp.mrp_production_form_view').id, 'form']], 'res_id': self.id, 'target': 'main', } - if self.user_has_groups('mrp.group_mrp_reception_report'): + elif self.user_has_groups('mrp.group_mrp_reception_report'): mos_to_show = self.filtered(lambda mo: mo.picking_type_id.auto_show_reception_report) lines = mos_to_show.move_finished_ids.filtered(lambda m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids) if lines: if any(mo.show_allocation for mo in mos_to_show): - action = mos_to_show.action_view_reception_report() - return action + another_action = mos_to_show.action_view_reception_report() + if report_actions: + return { + 'type': 'ir.actions.client', + 'tag': 'do_multi_print', + 'params': { + 'reports': report_actions, + 'anotherAction': another_action, + } + } + if another_action: + return another_action return True context = self.env.context.copy() context = {k: v for k, v in context.items() if not k.startswith('default_')} for k, v in context.items(): if k.startswith('skip_'): context[k] = False - action = { + another_action = { 'res_model': 'mrp.production', 'type': 'ir.actions.act_window', 'context': dict(context, mo_ids_to_backorder=None) } if len(backorders) == 1: - action.update({ + another_action.update({ + 'views': [[False, 'form']], 'view_mode': 'form', 'res_id': backorders[0].id, }) else: - action.update({ + another_action.update({ 'name': _("Backorder MO"), 'domain': [('id', 'in', backorders.ids)], + 'views': [[False, 'list'], [False, 'form']], 'view_mode': 'tree,form', }) - return action + if report_actions: + return { + 'type': 'ir.actions.client', + 'tag': 'do_multi_print', + 'params': { + 'reports': report_actions, + 'anotherAction': another_action, + } + } + return another_action def pre_button_mark_done(self): self._button_mark_done_sanity_checks() @@ -2584,3 +2615,14 @@ class MrpProduction(models.Model): if missing_lot_id_products: error_msg = _('You need to supply Lot/Serial Number for products:') + missing_lot_id_products raise UserError(error_msg) + + def _get_autoprint_done_report_actions(self): + """ Reports to auto-print when MO is marked as done + """ + report_actions = [] + productions_to_print = self.filtered(lambda p: p.picking_type_id.auto_print_done_production_order) + if productions_to_print: + 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) + return report_actions diff --git a/addons/mrp/models/stock_picking.py b/addons/mrp/models/stock_picking.py index 83f20ec5892..f53dacb1897 100644 --- a/addons/mrp/models/stock_picking.py +++ b/addons/mrp/models/stock_picking.py @@ -26,6 +26,10 @@ class StockPickingType(models.Model): help="Allow automatic consumption of tracked components that are reserved", ) + 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.") + @api.depends('code') def _compute_use_create_lots(self): for picking_type in self: diff --git a/addons/mrp/views/stock_picking_views.xml b/addons/mrp/views/stock_picking_views.xml index cdaf45c8130..32686e49264 100644 --- a/addons/mrp/views/stock_picking_views.xml +++ b/addons/mrp/views/stock_picking_views.xml @@ -138,6 +138,26 @@ + + + + + + + +
+ Odoo opens a PDF preview by default. If you want to print instantly, + install the IoT App on a computer that is on the same local network as the + barcode operator and configure the routing of the reports. + + Documentation + +
+
+
+
+