From 048f6e68f3e9020ea729a2dabc2138068ef19c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Mon, 1 Oct 2018 10:03:34 +0200 Subject: [PATCH] [10.0][FIX] stock_inventory_revaluation: unable to revaluate multiple quants with real method --- stock_inventory_revaluation/__manifest__.py | 2 +- .../models/stock_inventory_revaluation.py | 6 ++-- .../tests/test_stock_inventory_revaluation.py | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/stock_inventory_revaluation/__manifest__.py b/stock_inventory_revaluation/__manifest__.py index 9d0d1733f..b8abd9f47 100644 --- a/stock_inventory_revaluation/__manifest__.py +++ b/stock_inventory_revaluation/__manifest__.py @@ -9,7 +9,7 @@ "name": "Stock Inventory Revaluation", "summary": "Introduces inventory revaluation as single point to change " "the valuation of products.", - "version": "10.0.1.0.0", + "version": "10.0.1.1.0", "author": "Eficent Business and IT Consulting Services S.L., " "Serpent Consulting Services Pvt. Ltd.," "Odoo Community Association (OCA)", diff --git a/stock_inventory_revaluation/models/stock_inventory_revaluation.py b/stock_inventory_revaluation/models/stock_inventory_revaluation.py index f94a3ec51..e84b55c9d 100644 --- a/stock_inventory_revaluation/models/stock_inventory_revaluation.py +++ b/stock_inventory_revaluation/models/stock_inventory_revaluation.py @@ -271,9 +271,9 @@ class StockInventoryRevaluation(models.Model): if self.product_id: amount_diff = 0.0 if self.product_id.cost_method == 'real': - if self.reval_quant_ids: - if self.reval_quant_ids.product_id == self.product_id: - amount_diff += self.reval_quant_ids.get_total_value() + for reval_quant in self.reval_quant_ids: + if reval_quant.product_id == self.product_id: + amount_diff += reval_quant.get_total_value() if amount_diff == 0.0: return True else: diff --git a/stock_inventory_revaluation/tests/test_stock_inventory_revaluation.py b/stock_inventory_revaluation/tests/test_stock_inventory_revaluation.py index 296d95485..c0553e063 100644 --- a/stock_inventory_revaluation/tests/test_stock_inventory_revaluation.py +++ b/stock_inventory_revaluation/tests/test_stock_inventory_revaluation.py @@ -393,3 +393,35 @@ class TestStockInventoryRevaluation(TransactionCase): self.assertEqual(len( invent_price_change_real.account_move_ids), 0, 'Accounting entries have not been removed after cancel') + + def test_inventory_revaluation_price_change_real_multi_quant(self): + """Test that the inventory is revaluated when the + inventory price for a product managed under real costing method is + changed even if they are multple quant to revaluate""" + # Create an Inventory Revaluation for real cost product + + location = self.env.ref('stock.stock_location_components') + self._update_product_qty(self.product_real_1, location, 1) + + revaluation_type = 'price_change' + invent_price_change_real = \ + self._create_inventory_revaluation( + revaluation_type, + self.product_real_1) + + # Create an Inventory Revaluation Line Quant + date_from = date.today() - timedelta(1) + self._get_quant(date_from, invent_price_change_real) + + invent_price_change_real.sudo(self.user1).button_post() + + expected_result = (10.00 - 8.00) * 11.00 + self.assertEqual(len( + invent_price_change_real.account_move_ids[0].line_ids), 2, + 'Incorrect accounting entry generated') + + for move_line in invent_price_change_real.account_move_ids[0].line_ids: + if move_line.account_id == self.account_inventory: + self.assertEqual(move_line.credit, expected_result, + 'Incorrect inventory revaluation for ' + 'type Price Change.')