From 2cf99aa45290eb94c82c9d1c18c7897f1caa5ba0 Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Tue, 29 Aug 2023 10:46:40 +0530 Subject: [PATCH] [FIX] web: groupby date for pivot view When user tries to apply any Group By as date or datetime in the pivot view and the column value of pivot view is also a date or dateime, the traceback will be generated. To reproduce the issue: - Install Point of Sale - Go to 'Reporting' and click on 'Orders' - Select pivot view - Go to Group By and select 'Order Date' same as column value - Issue can be produce in the same way in other modules, such as - 'sale', 'sale_subscription', 'crm', 'planning', 'hr_expense' etc. Error: TypeError: can only concatenate str (not "relativedelta") to str The issue is occurring because we are getting duplicate values in groupby like ['date:month', 'date:month'] while calling orm method over here - https://github.com/odoo/odoo/blob/6cf3b617d8082df5820283d07e6623b7684cefdd/addons/web/static/src/core/orm_service.js#L143 To solve this issue groupby has been passed into a Set so that no duplicate values occurs in groupby. sentry-4262719543 closes odoo/odoo#137550 X-original-commit: de8e6a901b780d8c10484edae5ec1fe6b9fc7d3c Signed-off-by: Luca Vitali (luvi) --- addons/web/static/src/core/orm_service.js | 1 + .../web/static/tests/core/orm_service_tests.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/addons/web/static/src/core/orm_service.js b/addons/web/static/src/core/orm_service.js index f0703180f1f..c5f43cd1fe9 100644 --- a/addons/web/static/src/core/orm_service.js +++ b/addons/web/static/src/core/orm_service.js @@ -189,6 +189,7 @@ export class ORM { validateArray("domain", domain); validatePrimitiveList("fields", "string", fields); validatePrimitiveList("groupby", "string", groupby); + groupby = [...new Set(groupby)]; return this.call(model, "read_group", [], { ...kwargs, domain, fields, groupby }); } diff --git a/addons/web/static/tests/core/orm_service_tests.js b/addons/web/static/tests/core/orm_service_tests.js index c6ba0299bd6..2e2fc0f3b2e 100644 --- a/addons/web/static/tests/core/orm_service_tests.js +++ b/addons/web/static/tests/core/orm_service_tests.js @@ -297,6 +297,23 @@ QUnit.test("readGroup method", async (assert) => { }); }); +QUnit.test("test readGroup method removes duplicate values from groupby", async (assert) => { + const [query, rpc] = makeFakeRPC(); + serviceRegistry.add("rpc", rpc); + const env = await makeTestEnv(); + await env.services.orm.readGroup( + "sale.order", + [["user_id", "=", 2]], + ["amount_total:sum"], + ["date_order:month", "date_order:month"], + { offset: 1 } + ); + assert.strictEqual(query.route, "/web/dataset/call_kw/sale.order/read_group"); + assert.deepEqual(query.params.kwargs.groupby, ["date_order:month"], + "Duplicate values should be removed from groupby" + ); +}); + QUnit.test("searchRead method", async (assert) => { const [query, rpc] = makeFakeRPC(); serviceRegistry.add("rpc", rpc);