From 13e54c2f9ba3733f6717fc56130adf49e59407e2 Mon Sep 17 00:00:00 2001 From: "Guillaume (guva)" Date: Thu, 22 Jul 2021 12:56:13 +0000 Subject: [PATCH] [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 Signed-off-by: guva-odoo --- .../report/vendor_delay_report.py | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/addons/purchase_stock/report/vendor_delay_report.py b/addons/purchase_stock/report/vendor_delay_report.py index 1312b35a3cc..ef55b2ca434 100644 --- a/addons/purchase_stock/report/vendor_delay_report.py +++ b/addons/purchase_stock/report/vendor_delay_report.py @@ -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