[FIX] mail: clear groupBy from ActivityModel load

This commit fixes issues that could happen when a groupBy is present
in the load params from the ActivityModel. Before the rewrite of the
view to Owl, this code was present but was forgotten. This causes
crashes whenever web_search_read is then called, leading to undefined
record in the template, and crashing the view.

Now, the groupBy param (if present) is replaced by an empty array.

A test has been added to verify that during the load, even if the
ActivityModel has received a groupBy in its load parameters.

closes odoo/odoo#124215

X-original-commit: b6fa8ec174f5467baaed32b0c12acd0224757281
Signed-off-by: Dardenne Florent (dafl) <dafl@odoo.com>
This commit is contained in:
luvi
2023-06-08 09:10:04 +02:00
parent 23da6c637f
commit 2a1a388ffb
2 changed files with 40 additions and 0 deletions
@@ -14,6 +14,9 @@ export class ActivityModel extends RelationalModel {
async load(params = {}) {
this.originalDomain = params.domain ? [...params.domain] : [];
params.domain?.push(["activity_ids", "!=", false]);
if (params && "groupBy" in params) {
params.groupBy = [];
}
this.activityData = await this.fetchActivityData(params);
await super.load(params);
}
@@ -1,5 +1,6 @@
/** @odoo-module **/
import { ActivityModel } from "@mail/views/activity/activity_model";
import { ActivityRenderer } from "@mail/views/activity/activity_renderer";
import { start, startServer } from "@mail/../tests/helpers/test_utils";
@@ -529,6 +530,42 @@ QUnit.module("test_mail", {}, function () {
);
});
QUnit.test("activity view: group_by in the action has no effect", async function (assert) {
assert.expect(1);
patchWithCleanup(ActivityModel.prototype, {
async load(params) {
// force params to have a groupBy set, the model should ignore this value during the load
params.groupBy = ["user_id"];
await this._super(params);
},
});
serverData.actions = {
1: {
id: 1,
name: "MailTestActivity Action",
res_model: "mail.test.activity",
type: "ir.actions.act_window",
views: [[false, "activity"]],
},
};
const mockRPC = (route, args) => {
if (args.method === "get_activity_data") {
assert.strictEqual(
args.kwargs.groupby,
undefined,
"groupby should have been removed from the load params"
);
}
};
const { webClient } = await start({ serverData, mockRPC });
await doAction(webClient, 1);
});
QUnit.test(
"activity view: search more to schedule an activity for a record of a respecting model",
async function (assert) {