[FIX] purchase_stock : issue with pivot pivot_view

Step to reproduce

- Purchase >> reporting
- Filters > choose a Vendor
- Filters > Effective Date Last Year
- Toggle Studio
- Add Pivot View and close
- Measures > On-Time Delivery Rate

Got a traceback, the read_group method didn't take into account
the aggregate functions.

opw-2600230

closes odoo/odoo#74672

X-original-commit: ca3821aa35bece74a461a47ea8a8f5e680df83a7
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
Signed-off-by: guva-odoo <guva-odoo@users.noreply.github.com>
This commit is contained in:
Guillaume (guva)
2021-08-03 18:01:14 +00:00
parent 6eb7a45df1
commit 13e54c2f9b
@@ -53,16 +53,30 @@ GROUP BY m.id
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
if 'on_time_rate' not in fields:
if all('on_time_rate' not in field for field in fields):
res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
return res
fields.remove('on_time_rate')
if 'qty_total' not in fields:
fields.append('qty_total')
if 'qty_on_time' not in fields:
fields.append('qty_on_time')
for field in fields:
if 'on_time_rate' not in field:
continue
fields.remove(field)
agg = field.split(':')[1:]
if agg and agg[0] != 'sum':
raise NotImplementedError('Aggregate functions other than \':sum\' are not allowed.')
qty_total = field.replace('on_time_rate', 'qty_total')
if qty_total not in fields:
fields.append(qty_total)
qty_on_time = field.replace('on_time_rate', 'qty_on_time')
if qty_on_time not in fields:
fields.append(qty_on_time)
break
res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
for group in res:
if group['qty_total'] == 0:
on_time_rate = 100