[FIX] mrp: handle keyError when workorder(s) deleted
If applied, this commit will solve the issue of keyError when we confirm the manufacturing order and work order (s) are deleted. Steps to produce: - Configure BOM with 'Operations'. - Set operations in the 'Consumed in Operation' field which is in 'Components'. - Create MO using that BOM. - Delete the work order(s) from MO. - Click on the 'Confirm' button. Fix this issue when the work order is not available for that operation, setting False in stock.move record(s). sentry - 4171798106 closes odoo/odoo#123033 X-original-commit: 36e02b91e88c5e014d132643b6ffb24a71342d6c Signed-off-by: Parth Solanki (paso) <paso@odoo.com> Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -1282,7 +1282,7 @@ class MrpProduction(models.Model):
|
||||
for move in (self.move_raw_ids | self.move_finished_ids):
|
||||
if move.operation_id:
|
||||
move.write({
|
||||
'workorder_id': workorder_per_operation[move.operation_id].id
|
||||
'workorder_id': workorder_per_operation[move.operation_id].id if move.operation_id in workorder_per_operation else False
|
||||
})
|
||||
else:
|
||||
bom = move.bom_line_id.bom_id if (move.bom_line_id and move.bom_line_id.bom_id in workorder_boms) else self.bom_id
|
||||
|
||||
@@ -3274,3 +3274,14 @@ class TestMrpOrder(TestMrpCommon):
|
||||
|
||||
# Only duration from the workcenter specific capacity setup/cleanup times since there is one defined for this product.
|
||||
self.assertEqual(production.workorder_ids[0].duration_expected, 15.0, "Capacity setup time (5) + capacity cleanup time (10)")
|
||||
|
||||
def test_unlink_workorder_with_consumed_operations(self):
|
||||
self.bom_3.bom_line_ids[0].operation_id = self.bom_3.operation_ids[0].id
|
||||
self.bom_3.bom_line_ids[1].operation_id = self.bom_3.operation_ids[1].id
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.bom_id = self.bom_3
|
||||
mo = mo_form.save()
|
||||
mo.workorder_ids[1].unlink()
|
||||
mo.action_confirm()
|
||||
self.assertEqual(mo.state, 'confirmed')
|
||||
self.assertEqual(len(mo.workorder_ids), 2)
|
||||
|
||||
Reference in New Issue
Block a user