From 9d3d0d027c5eb30f610d8316dd03c33b54d57d27 Mon Sep 17 00:00:00 2001 From: kado-odoo Date: Thu, 2 Jun 2022 06:46:55 +0000 Subject: [PATCH] [FIX] mrp: prevent byproduct missing record error Before this commit, there was a bug with MO by-product moves: - With a newly created MO, confirm MO and after manually add `Produced` quantity in By-Products and change quantity producing in MO and save the record then it raises the missing record error. same issues was fixed here https://github.com/odoo/odoo/commit/c1768d00e8eb76af32ead10f75ce3d09a5aefac9 but forgot to fix same in write method. so this commit is fix same but in write method TaskID - 2799848 closes odoo/odoo#92728 Signed-off-by: Tiffany Chang --- addons/mrp/models/mrp_production.py | 3 +++ addons/mrp/tests/test_byproduct.py | 1 + 2 files changed, 4 insertions(+) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 0d9e9a1ee7f5c..062bebd4fcb29 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -727,6 +727,9 @@ def _check_production_lines(self): raise ValidationError(_("The component %s should not be the same as the product to produce.") % production.product_id.display_name) def write(self, vals): + if 'move_byproduct_ids' in vals and 'move_finished_ids' not in vals: + vals['move_finished_ids'] = vals['move_byproduct_ids'] + del vals['move_byproduct_ids'] if 'workorder_ids' in self: production_to_replan = self.filtered(lambda p: p.is_planned) res = super(MrpProduction, self).write(vals) diff --git a/addons/mrp/tests/test_byproduct.py b/addons/mrp/tests/test_byproduct.py index 0249e2cc489ed..269cafae2e959 100644 --- a/addons/mrp/tests/test_byproduct.py +++ b/addons/mrp/tests/test_byproduct.py @@ -69,6 +69,7 @@ def test_00_mrp_byproduct(self): # I consume and produce the production of products. # I create record for selecting mode and quantity of products to produce. mo_form = Form(mnf_product_a) + mnf_product_a.move_byproduct_ids.quantity_done = 2 mo_form.qty_producing = 2.00 mnf_product_a = mo_form.save() # I finish the production order.