diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index c356096d4e9..41efa20d3fb 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -236,16 +236,16 @@ class ProductProduct(models.Model): svl_vals_list = [] company_id = self.env.company + price_unit_prec = self.env['decimal.precision'].precision_get('Product Price') + rounded_new_price = float_round(new_price, precision_digits=price_unit_prec) for product in self: if product.cost_method not in ('standard', 'average'): continue quantity_svl = product.sudo().quantity_svl if float_compare(quantity_svl, 0.0, precision_rounding=product.uom_id.rounding) <= 0: continue - digits = self.env['decimal.precision'].precision_get('Product Price') - rounded_new_price = float_round(new_price, precision_digits=digits) - diff = rounded_new_price - product.standard_price - value = company_id.currency_id.round(quantity_svl * diff) + value_svl = product.sudo().value_svl + value = company_id.currency_id.round((rounded_new_price * quantity_svl) - value_svl) if company_id.currency_id.is_zero(value): continue diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index 84638b82b15..c1f3ee2d36b 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -3968,3 +3968,16 @@ class TestStockValuation(TransactionCase): self.assertEqual(self.product1.quantity_svl, 12) move.quantity_done = 2 self.assertEqual(self.product1.quantity_svl, 24) + + def test_average_manual_price_change(self): + """ + When doing a Manual Price Change, an SVL is created to update the value_svl. + This test check that the value of this SVL is correct and does result in new_std_price * quantity. + To do so, we create 2 In moves, which result in a standard price rounded at $5.29, the non-rounded value ≃ 5.2857. + Then we update the standard price to $7 + """ + self.product1.categ_id.property_cost_method = 'average' + self._make_in_move(self.product1, 5, unit_cost=5) + self._make_in_move(self.product1, 2, unit_cost=6) + self.product1.write({'standard_price': 7}) + self.assertEqual(self.product1.value_svl, 49)