[FIX] mrp_account: AVCO product valuation with component cost 0

Steps to reproduce:
- Create a manufactured product P with AVCO valuation
- On the bom of the previous product add a component C with unit cost 5$
- Manufacture product P (Unit cost correct so far 5$)
- Change component cost to 0 and manufacture again
- Unit cost of P is still 5$ were it should be 2.5$

Bug:
since the move unit price is 0 the standard price of the product P is
used insted for the valuation of the newly created qty

Fix:
force unit price to 0 in the case of manufacturing

opw-3374462

closes odoo/odoo#132047

X-original-commit: f6c2b5368e3abdc292e66dc04efc4031eb12f742
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid
2023-08-16 17:48:19 +02:00
committed by William Henrotin
parent 127147bbab
commit 1fb4d356b5
2 changed files with 17 additions and 0 deletions
+4
View File
@@ -26,6 +26,10 @@ class StockMove(models.Model):
return distribution
return super()._get_analytic_distribution()
def _should_force_price_unit(self):
self.ensure_one()
return self.picking_type_id.code == 'mrp_operation' or super()._should_force_price_unit()
def _ignore_automatic_valuation(self):
return bool(self.raw_material_production_id)
@@ -240,9 +240,22 @@ class TestMrpValuationStandard(TestMrpValuationCommon):
self.assertEqual(self.product1.value_svl, 8.8 * 2)
self.assertEqual(self.component.quantity_svl, 0)
self.assertEqual(self.product1.quantity_svl, 2)
self.assertEqual(self.product1.standard_price, 8.8)
self._make_out_move(self.product1, 1)
self.assertEqual(self.product1.value_svl, 8.8)
# Update component price
self.component.standard_price = 0
self._make_in_move(self.component, 3)
mo = self._make_mo(self.bom, 3)
self._produce(mo)
mo.button_mark_done()
self.assertEqual(self.product1.value_svl, 8.8)
self.assertEqual(self.product1.quantity_svl, 4)
self.assertEqual(self.product1.standard_price, 2.2)
def test_std_std_1(self):
self.component.product_tmpl_id.categ_id.property_cost_method = 'standard'
self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'