From 569bd997814f27301bb8ab80add480c8a56095b9 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Fri, 16 Jul 2021 05:20:50 +0000 Subject: [PATCH] [13.0][FIX] stock_account: average unit cost price When the cost of a product is set to a value below the currency rounding the average purchase cost price will be wrongly set to zero. It can happen for product sold in large quantity, that the cost of one product must be smaller than the smallest unit of currency. Instead of doing the zero check with currency precision using the product price precision, which is the one used for the `standard_price` fields, makes more sense and fixes the problem. opw-2601121 closes odoo/odoo#73985 X-original-commit: 251be6b943ea8c3f274bb0863d0af3f7c6b8d10d Signed-off-by: Arnold Moyaux --- addons/stock_account/models/stock_move.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index dc5a95e8415..d6154505952 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -32,10 +32,11 @@ class StockMove(models.Model): """ Returns the unit price to value this stock move """ self.ensure_one() price_unit = self.price_unit + precision = self.env['decimal.precision'].precision_get('Product Price') # If the move is a return, use the original move's price unit. if self.origin_returned_move_id and self.origin_returned_move_id.sudo().stock_valuation_layer_ids: price_unit = self.origin_returned_move_id.sudo().stock_valuation_layer_ids[-1].unit_cost - return not self.company_id.currency_id.is_zero(price_unit) and price_unit or self.product_id.standard_price + return not float_is_zero(price_unit, precision) and price_unit or self.product_id.standard_price @api.model def _get_valued_types(self):