From 58a3fa82ff8757d9118f5d775cf11af402ee47a8 Mon Sep 17 00:00:00 2001 From: uso-odoo Date: Fri, 31 Mar 2023 06:48:17 +0000 Subject: [PATCH] [FIX] mrp : prevent traceback while operation use in bom When Operation is 'Archive' and it is still in use as 'Consumed in Operation' in bom while creating Manufacturing Order and confirming it, KeyError will be generated. Steps to Produce:- 1) Create a new product, create bom for that product, add components, and create or add at least 2 operations to the BoM. 2) In the components of 'Consumed in Operation' add the newly created operation. 3) Now, Archive one operation. 4) Create new Manufacturing Order with a newly created BOM 5) Try to confirm it. KeyError will be generated. By applying this commit, if there are no operations left after archiving one linked to the component then the server error won't occur sentry - 4042593205 closes odoo/odoo#119098 X-original-commit: ba2364f9188ff44c68a1b86d5029884815a33216 Signed-off-by: Tiffany Chang --- addons/mrp/models/mrp_routing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/mrp/models/mrp_routing.py b/addons/mrp/models/mrp_routing.py index 309ef14f6a7..c53d4d4e528 100644 --- a/addons/mrp/models/mrp_routing.py +++ b/addons/mrp/models/mrp_routing.py @@ -105,6 +105,12 @@ class MrpRoutingWorkcenter(models.Model): if not self._check_m2m_recursion('blocked_by_operation_ids'): raise ValidationError(_("You cannot create cyclic dependency.")) + def action_archive(self): + res = super().action_archive() + bom_lines = self.env['mrp.bom.line'].search([('operation_id', 'in', self.ids)]) + bom_lines.write({'operation_id': False}) + return res + def copy_to_bom(self): if 'bom_id' in self.env.context: bom_id = self.env.context.get('bom_id')