From 0552a1246f5928fd1b0835d7dd8f014e1ad6fb4a Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 30 Nov 2020 14:35:56 +0000 Subject: [PATCH] [FIX] stock_account, stock_landed_costs: do not create SVL for consumable The creation of a Stock Valuation Layer is useless in case of a Consumable product. At best it is useless, at worst it causes inconsistencies when the user switch from a Consumable to a Storable type. closes odoo/odoo#62936 X-original-commit: 7e9d052beabe15d932e5d403f8ca2f4837c7d24f Signed-off-by: Nicolas Martinelli (nim) --- addons/sale_stock_margin/tests/test_sale_stock_margin.py | 1 + addons/stock_account/models/stock_move.py | 2 +- addons/stock_landed_costs/tests/test_stock_landed_costs.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale_stock_margin/tests/test_sale_stock_margin.py b/addons/sale_stock_margin/tests/test_sale_stock_margin.py index 5de45112b1b..09647269020 100644 --- a/addons/sale_stock_margin/tests/test_sale_stock_margin.py +++ b/addons/sale_stock_margin/tests/test_sale_stock_margin.py @@ -30,6 +30,7 @@ class TestSaleStockMargin(TestStockValuationCommon): def _create_product(self): product_template = self.env['product.template'].create({ 'name': 'Super product', + 'type': 'product', }) product_template.categ_id.property_cost_method = 'fifo' return product_template.product_variant_ids diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index 2c90c4af584..033aa1149ac 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -234,7 +234,7 @@ class StockMove(models.Model): # Init a dict that will group the moves by valuation type, according to `move._is_valued_type`. valued_moves = {valued_type: self.env['stock.move'] for valued_type in self._get_valued_types()} for move in self: - if float_is_zero(move.quantity_done, precision_rounding=move.product_uom.rounding): + if float_is_zero(move.quantity_done, precision_rounding=move.product_uom.rounding) or move.product_id.type == 'consu': continue for valued_type in self._get_valued_types(): if getattr(move, '_is_%s' % valued_type)(): diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs.py b/addons/stock_landed_costs/tests/test_stock_landed_costs.py index 89847cedc56..9e86cdf6c0e 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs.py @@ -20,6 +20,7 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): 'weight': 10, 'volume': 1, 'categ_id': self.stock_account_product_categ.id, + 'type': 'product', }) product_landed_cost_2 = self.env['product.product'].create({ @@ -27,6 +28,7 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): 'weight': 20, 'volume': 1.5, 'categ_id': self.stock_account_product_categ.id, + 'type': 'product', }) self.assertEqual(product_landed_cost_1.value_svl, 0)