diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 9b792186481..cb4c247d244 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -223,7 +223,8 @@ class ProductProduct(models.Model): quantity_svl = product.sudo().quantity_svl if float_compare(quantity_svl, 0.0, precision_rounding=product.uom_id.rounding) <= 0: continue - diff = new_price - product.standard_price + rounded_new_price = company_id.currency_id.round(new_price) + diff = rounded_new_price - product.standard_price value = company_id.currency_id.round(quantity_svl * diff) if company_id.currency_id.is_zero(value): continue @@ -231,7 +232,7 @@ class ProductProduct(models.Model): svl_vals = { 'company_id': company_id.id, 'product_id': product.id, - 'description': _('Product value manually modified (from %s to %s)') % (product.standard_price, new_price), + 'description': _('Product value manually modified (from %s to %s)') % (product.standard_price, rounded_new_price), 'value': value, 'quantity': 0, } diff --git a/addons/stock_account/tests/test_stock_valuation_layer_revaluation.py b/addons/stock_account/tests/test_stock_valuation_layer_revaluation.py index d84f865229a..f53e7f08fbf 100644 --- a/addons/stock_account/tests/test_stock_valuation_layer_revaluation.py +++ b/addons/stock_account/tests/test_stock_valuation_layer_revaluation.py @@ -125,6 +125,39 @@ class TestStockValuationLayerRevaluation(TestStockValuationCommon): self.assertEqual(len(credit_lines), 1) self.assertEqual(credit_lines[0].account_id.id, self.stock_valuation_account.id) + def test_stock_valuation_layer_revaluation_avco_rounding_2_digits(self): + """ + Check that the rounding of the new price (cost) is equivalent to the rounding of the standard price (cost) + The check is done indirectly via the layers valuations. + If correct => rounding method is correct too + """ + self.product1.categ_id.property_cost_method = 'average' + + self.env['decimal.precision'].search([ + ('name', '=', 'Product Price'), + ]).digits = 2 + self.product1.write({'standard_price': 0}) + + # First Move + self.product1.write({'standard_price': 0.022}) + self._make_in_move(self.product1, 10000) + + self.assertEqual(self.product1.standard_price, 0.02) + self.assertEqual(self.product1.quantity_svl, 10000) + + layer = self.product1.stock_valuation_layer_ids + self.assertEqual(layer.value, 200) + + # Second Move + self.product1.write({'standard_price': 0.053}) + + self.assertEqual(self.product1.standard_price, 0.05) + self.assertEqual(self.product1.quantity_svl, 10000) + + layers = self.product1.stock_valuation_layer_ids + self.assertEqual(layers[0].value, 200) + self.assertEqual(layers[1].value, 300) + def test_stock_valuation_layer_revaluation_fifo(self): self.product1.categ_id.property_cost_method = 'fifo' context = {