[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) <whe@odoo.com>
Signed-off-by: Eteil Junior Djoumatchoua (etdj) <etdj@odoo.com>
This commit is contained in:
Eteil Djoumatchoua(etdj)
2023-09-13 03:37:59 +00:00
parent 4a24d76170
commit 81136e4dc9
2 changed files with 10 additions and 0 deletions
@@ -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)
@@ -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)