From 81136e4dc98211a705f66bf007da52c92addfa7b Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua(etdj)" Date: Mon, 21 Aug 2023 10:28:07 +0200 Subject: [PATCH] [FIX] stock_account: Display the value field on StockQuant list view Steps to reproduce: - Go to Inventory -> Reporting -> Location. - Enable the 'Value(value)' to be displayed on the view. - Group by Location. Issue: There is no value displayed under the 'value' column Reason: When overriding the ``_read_group()`` in ``StockQuant``, in the stack it's called by the ``BaseMode.read_group()`` where the aggregated fields are computed. As ``StockQuant.value`` is a computed field(not stored), it will never be part of it https://github.com/odoo/odoo/blob/6d785a9cacf9f592eb76e8edccabf514bf348f08/odoo/models.py#L2516. So when entering the ``StockQuant._read_group()``, ``{'value:sum'}.isdisjoint(aggregates)`` will always be true. opw-3440766 closes odoo/odoo#135150 X-original-commit: 4fb6415c8ddfbcf691b92441e72fbfda6f2f3875 Signed-off-by: William Henrotin (whe) Signed-off-by: Eteil Junior Djoumatchoua (etdj) --- addons/stock_account/models/stock_quant.py | 6 ++++++ addons/stock_account/tests/test_stockvaluation.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/addons/stock_account/models/stock_quant.py b/addons/stock_account/models/stock_quant.py index 441a54f5f82..9d356b22329 100644 --- a/addons/stock_account/models/stock_quant.py +++ b/addons/stock_account/models/stock_quant.py @@ -61,6 +61,12 @@ class StockQuant(models.Model): return result + @api.model + def read_group(self, domain, fields, *args, **kwargs): + if 'value' in fields: + fields = ['value:sum' if f == 'value' else f for f in fields] + return super().read_group(domain, fields, *args, **kwargs) + def _apply_inventory(self): for accounting_date, inventory_ids in groupby(self, key=lambda q: q.accounting_date): inventories = self.env['stock.quant'].concat(*inventory_ids) diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index 0d79fc49b5a..7ee38537e98 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -3989,5 +3989,9 @@ class TestStockValuation(TransactionCase): self.product1.categ_id.property_cost_method = 'average' self._make_in_move(self.product1, 5, unit_cost=5) self._make_in_move(self.product1, 2, unit_cost=6) + + res = self.env['stock.quant'].read_group([('product_id', '=', self.product1.id)], ['value'], ['product_id']) + self.assertEqual(res[0]['value'], 5 * 5 + 2 * 6) + self.product1.write({'standard_price': 7}) self.assertEqual(self.product1.value_svl, 49)