[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) <luvi@odoo.com>
This commit is contained in:
Saurabh Choraria
2023-10-04 20:52:42 +00:00
parent 6ffea84866
commit 2cf99aa452
2 changed files with 18 additions and 0 deletions
@@ -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 });
}
@@ -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);