From 8a7f221c91a0571bb1da4548bf22543e9503b63d Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 17 May 2023 10:09:55 +0000 Subject: [PATCH] [FIX] project_purchase: use model indicator in query This commit adds alias table to be sure the `analytic_distribution` column will not be ambiguous because another table could have the same column name. closes #121611 closes #110291 closes odoo/odoo#131991 X-original-commit: 253479633b32383e141fe2ca2ca7395f22651485 Signed-off-by: Xavier Bol (xbo) --- addons/project_purchase/models/project_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/project_purchase/models/project_project.py b/addons/project_purchase/models/project_project.py index 2a880f7d3f5..0eb3004b80c 100644 --- a/addons/project_purchase/models/project_project.py +++ b/addons/project_purchase/models/project_project.py @@ -22,10 +22,10 @@ class Project(models.Model): query.add_where('purchase_order_line.analytic_distribution ?| %s', [[str(account_id) for account_id in self.analytic_account_id.ids]]) query_string, query_param = query.select( - 'jsonb_object_keys(analytic_distribution) as account_id', + 'jsonb_object_keys(purchase_order_line.analytic_distribution) as account_id', 'COUNT(DISTINCT(order_id)) as purchase_order_count', ) - query_string = f"{query_string} GROUP BY jsonb_object_keys(analytic_distribution)" + query_string = f"{query_string} GROUP BY jsonb_object_keys(purchase_order_line.analytic_distribution)" self._cr.execute(query_string, query_param) data = {int(record.get('account_id')): record.get('purchase_order_count') for record in self._cr.dictfetchall()}