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'