From d7246ef7868f52d594150e35ea0402fd95149f98 Mon Sep 17 00:00:00 2001 From: Ahmed Khalaf Date: Tue, 13 Dec 2022 11:20:01 +0000 Subject: [PATCH] [FIX] mrp: fix change MO qty to produce Before this commit, if a user changes a MO move qty to 0 and then tries to change the MO qty to produce, an error occurs. The move with 0 qty is no longer cancelled or unlinked as this was not the intenteded behavior. Since the change production wizard no longer deletes cancelled moves a test was updated accordingly. closes odoo/odoo#108534 Taskid: 3082611 X-original-commit: 39abadb30dc8fab6b2a1ca24cb2916ab148fb5fa Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Ahmed Khalaf --- addons/mrp/models/mrp_production.py | 8 -------- addons/mrp/tests/test_order.py | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 0f34081ae06..93ff38c54dc 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1061,7 +1061,6 @@ class MrpProduction(models.Model): def _update_raw_moves(self, factor): self.ensure_one() update_info = [] - move_to_unlink = self.env['stock.move'] moves_to_assign = self.env['stock.move'] procurements = [] for move in self.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel')): @@ -1080,14 +1079,7 @@ class MrpProduction(models.Model): move.product_id, procurement_qty, move.product_uom, move.location_id, move.name, move.origin, move.company_id, values)) update_info.append((move, old_qty, new_qty)) - else: - if move.quantity_done > 0: - raise UserError(_('Lines need to be deleted, but can not as you still have some quantities to consume in them. ')) - move._action_cancel() - move_to_unlink |= move - moves_to_assign._action_assign() - move_to_unlink.unlink() if procurements: self.env['procurement.group'].run(procurements) return update_info diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 6284f130b31..7c47ea27f88 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -874,10 +874,10 @@ class TestMrpOrder(TestMrpCommon): mo.move_raw_ids.filtered(lambda m: m.state != 'done')[0].quantity_done = 0 update_quantity_wizard.change_prod_qty() - self.assertEqual(len(mo.move_raw_ids), 2) + self.assertEqual(len(mo.move_raw_ids), 4) mo.button_mark_done() - self.assertTrue(all(s == 'done' for s in mo.move_raw_ids.mapped('state'))) + self.assertTrue(all(s in ['done', 'cancel'] for s in mo.move_raw_ids.mapped('state'))) self.assertEqual(sum(mo.move_raw_ids.mapped('move_line_ids.reserved_uom_qty')), 0) def test_consumption_strict_1(self):