[FIX] mrp: clear finished moves

The finished move of a production order should be deleted if we change
the product to avoid having draft stock move detached from any business
documents

closes odoo/odoo#118957

Task: 3172098
X-original-commit: 4478560d7769a8a795a94aead875e02d1394dd71
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
William Henrotin
2023-04-24 16:57:41 +02:00
committed by Adrien Widart (awt)
parent 0fa36d664b
commit d9972ddec4
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -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()
+14
View File
@@ -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