From 7a1c7870a9ddd904797f452caaf424310bccac8e Mon Sep 17 00:00:00 2001 From: Walid Date: Mon, 2 Oct 2023 15:01:18 +0200 Subject: [PATCH] [FIX] mrp_account: correct component price unbuild Steps to reproduce: - Create a component C (automated/FIFO) - Create and confirm two PO for C qty: 1, price: 10 qty: 1, price: 20 - Make an MO with C as a component - Unbuild that MO Bug: The valuation of the new component C is wrong, the new move in is valued at the current product cost instead of its original value. Fix: create moves as a return to get the correct value opw-3379457 closes odoo/odoo#137353 X-original-commit: d42238cc75fe6621c1eb893395856870c8bfbafb Signed-off-by: William Henrotin (whe) Signed-off-by: Walid Hanniche (waha) --- addons/mrp/models/mrp_unbuild.py | 1 + .../tests/test_valuation_layers.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index f6d4c321c06..dc875dbcf16 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -258,6 +258,7 @@ class MrpUnbuild(models.Model): 'warehouse_id': location_dest_id.warehouse_id.id, 'unbuild_id': self.id, 'company_id': move.company_id.id, + 'origin_returned_move_id': move.id, }) def _generate_move_from_bom_line(self, product, product_uom, quantity, bom_line_id=False, byproduct_id=False): diff --git a/addons/mrp_account/tests/test_valuation_layers.py b/addons/mrp_account/tests/test_valuation_layers.py index bcc20614f57..1389916d6d6 100644 --- a/addons/mrp_account/tests/test_valuation_layers.py +++ b/addons/mrp_account/tests/test_valuation_layers.py @@ -128,6 +128,28 @@ class TestMrpValuationStandard(TestMrpValuationCommon): self.assertEqual(self.product1.quantity_svl, 2) self.assertEqual(byproduct.quantity_svl, 2) + def test_fifo_unbuild(self): + """ This test creates an MO and then creates an unbuild + orders and checks the stock valuation. + """ + self.component.product_tmpl_id.categ_id.property_cost_method = 'fifo' + # --------------------------------------------------- + # MO + # --------------------------------------------------- + self._make_in_move(self.component, 1, 10) + self._make_in_move(self.component, 1, 20) + mo = self._make_mo(self.bom, 1) + self._produce(mo) + mo.button_mark_done() + self.assertEqual(self.component.value_svl, 20) + # --------------------------------------------------- + # Unbuild + # --------------------------------------------------- + unbuild_form = Form(self.env['mrp.unbuild']) + unbuild_form.mo_id = mo + unbuild_form.save().action_unbuild() + self.assertEqual(self.component.value_svl, 30) + def test_fifo_avco_1(self): self.component.product_tmpl_id.categ_id.property_cost_method = 'fifo' self.product1.product_tmpl_id.categ_id.property_cost_method = 'average'