diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 967df5bbf40..fa053312995 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -739,6 +739,8 @@ class MrpProduction(models.Model): Command.update(m.id, updated_values) for m in production.move_finished_ids ] continue + # delete to remove existing moves from database and clear to remove new records + production.move_finished_ids = [Command.delete(m) for m in production.move_finished_ids.ids] production.move_finished_ids = [Command.clear()] if production.product_id: production._create_update_move_finished() diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 3bb2b8c4e6c..28bdd0b2d7c 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3135,6 +3135,20 @@ class TestMrpOrder(TestMrpCommon): self.assertEqual(mo.move_raw_ids.quantity_done, 1.25) + def test_clear_finished_move(self): + """ Test that the finished moves created by the compute are correctly + erased after changing the finished product""" + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = self.product_1 + mo = mo_form.save() + self.assertEqual(len(mo.move_finished_ids), 1) + mo.product_id = self.product_2 + self.assertEqual(len(mo.move_finished_ids), 1) + self.assertFalse(self.env['stock.move'].search([ + ('product_id', '=', self.product_1.id), + ('state', '=', 'draft'), + ])) + def test_compute_picking_type_id(self): """ Test that the operation type set on the bom is set in the manufacturing order