From 71bc97c19b919f3241f9bd00186ed8573611837f Mon Sep 17 00:00:00 2001 From: "Pieter Claeys (clpi)" Date: Thu, 31 Mar 2022 13:27:01 +0000 Subject: [PATCH] [FIX] mrp: Preserve component registration steps on backorder creation Impacted versions: 15.0 Steps to reproduce (starting from ENTERPRISE 15.2): - enable Work Orders - create new BoM for a new product - add 1 operation w/ 1 step (e.g. Instructions) - add 1 component to BoM with operation_id (Consumed in Operation) = the operation - Create and confirm a MO with new BoM + 2 Quantity to Produce - Produce 1 product via the tablet view flow (i.e. complete instruction step + Validate 1 component in "Register Consumed Materials" step + Mark As Done) Current behaviour: Backorder is correctly created, but its workorder is missing the "Register Consumed Materials" step Expected behaviour: Step is correctly created Note: same issue occurs with Byproducts having an operation_id (i.e. "Produced in Operation") Issue is due to when _split_productions() first creates the backorders, they are created without move_raw_ids and move_finished_ids (see: _get_backorder_mo_vals()). When the backorders are created, they auto-create and auto-confirm their workorders. Since a quality point (e.g. operation step) exists for the workorder, the initial _action_confirm will _create_checks() for the quality point, but the "Register Consumed Materials" steps are created by the operation_id values in the move_raw_ids and move_finished_ids which haven't been set yet. This makes it so when the second _action_confirm() is called on the workorders (i.e. after their moves have been set) at the end of _split_productions(), the _create_checks() will be skipped because it assumes all the quality points have been created since one already exists. Task: 2800975 Community PR: https://github.com/odoo/odoo/pull/87681 Enterprise PR: https://github.com/odoo/enterprise/pull/26437 closes odoo/odoo#89486 X-original-commit: 67524eb948b7e122f33abf344b28b59bd81eb88d Related: odoo/enterprise#26534 Signed-off-by: Tiffany Chang --- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/mrp_workorder.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 7061d7aec07..0d92bbe6aae 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1551,7 +1551,7 @@ class MrpProduction(models.Model): backorder_sequence=next_seq )) - backorders = self.env['mrp.production'].create(backorder_vals_list) + backorders = self.env['mrp.production'].with_context(skip_confirm=True).create(backorder_vals_list) index = 0 production_to_backorders = {} diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 4783a0879c8..e3a7a811b60 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -448,6 +448,8 @@ class MrpWorkorder(models.Model): # Auto-confirm manually added workorders. # We need to go through `_action_confirm` for all workorders of the current productions to # make sure the links between them are correct. + if self.env.context.get('skip_confirm'): + return res to_confirm = res.filtered(lambda wo: wo.production_id.state in ("confirmed", "progress", "to_close")) to_confirm = to_confirm.production_id.workorder_ids to_confirm._action_confirm()