From a8398234cb7ffb06514a1944697e81dcbd96640d Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Wed, 25 Jan 2023 14:04:53 +0000 Subject: [PATCH] [FIX] stock_account: fix remaining qty in svl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a product category “Fifo”: - set the costing method to Fifo - Create a storable product “P1”: - category: All (costing method = standard) - Update the qty to 10 units - Go to inventory → Product variant → “P1” - Change the category from “All” to “Fifo” - Go to inventory → Reporting → stock valuation - Add “reaming_qty” field in the list view Problem: The empty_stock layer (the layer created to empty the product) has `remaining_qty` of -10 instead of 0 whereas we change from standard to Fifo The write method of `product.product` is triggered, leading to Product Variant having another category than Product Template when the write method of `product.template` is triggered opw-3138061 closes odoo/odoo#111911 X-original-commit: f6f5d4a27af5bad42c3c6c11ce681be631f43248 Signed-off-by: Djamel Touati (otd) Signed-off-by: William Henrotin (whe) --- addons/stock_account/models/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 63412a40136..2694989372b 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -203,7 +203,7 @@ class ProductProduct(models.Model): fifo_vals = self._run_fifo(abs(quantity), company) vals['remaining_qty'] = fifo_vals.get('remaining_qty') # In case of AVCO, fix rounding issue of standard price when needed. - if self.cost_method == 'average': + if self.product_tmpl_id.cost_method == 'average': rounding_error = currency.round(self.standard_price * self.quantity_svl - self.value_svl) if rounding_error: # If it is bigger than the (smallest number of the currency * quantity) / 2, @@ -215,7 +215,7 @@ class ProductProduct(models.Model): float_repr(rounding_error, precision_digits=currency.decimal_places), currency.symbol ) - if self.cost_method == 'fifo': + if self.product_tmpl_id.cost_method == 'fifo': vals.update(fifo_vals) return vals