From d98552c5c2d4d2d71ed154169c7b4d115f554a6c Mon Sep 17 00:00:00 2001 From: paso-odoo Date: Mon, 8 May 2023 06:48:17 +0000 Subject: [PATCH] [FIX] mrp: confirm MO with deleted WO If there are some dependencies between BoM's operations, a traceback will appear when the user removes one WO. Steps to produce: - From Manufacturing > Configuration: Enable Work Orders. - Open any Bills of Material. - In 'Miscellaneous' tab tick the 'Operation Dependencies' boolean. - Set 3 or more operations in the 'Operations' tab. - After saving the BOM add 'Blocked By' in the operations. - Now Create Manufacturing Order for that BOM. - Delete the one or more workorder(s) from mrp order. - Now click on the 'Confirm' button, and the error will be raised. The loop is incorrect because we iterate on the BoM's operations but the keys of the dict `workorder_per_operation` are based on the MO's work orders. Therefore, if we remove one WO, the dict will not have any key for the related operation, hence the traceback. sentry-4146643254 closes odoo/odoo#125990 X-original-commit: 15366af1774a571548a9c35e7dd8acbdc16ba71f Related: odoo/enterprise#42957 Signed-off-by: Adrien Widart (awt) Signed-off-by: Parth Solanki (paso) --- addons/mrp/models/mrp_production.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index c59d0057626..99ff5f512fa 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1353,7 +1353,10 @@ class MrpProduction(models.Model): self.allow_workorder_dependencies = self.bom_id.allow_operation_dependencies if self.allow_workorder_dependencies: for workorder in self.workorder_ids: - workorder.blocked_by_workorder_ids = [Command.link(workorder_per_operation[operation_id].id) for operation_id in workorder.operation_id.blocked_by_operation_ids] + workorder.blocked_by_workorder_ids = [Command.link(workorder_per_operation[operation_id].id) + for operation_id in + workorder.operation_id.blocked_by_operation_ids + if operation_id in workorder_per_operation] if not workorder.needed_by_workorder_ids: last_workorder_per_bom[workorder.operation_id.bom_id] = workorder else: