From 2a1a388ffb1b3d5fc8cf83bdad786edded43db05 Mon Sep 17 00:00:00 2001 From: luvi Date: Fri, 2 Jun 2023 08:23:29 +0000 Subject: [PATCH] [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) --- .../src/views/activity/activity_model.js | 3 ++ .../test_mail/static/tests/activity_tests.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/addons/mail/static/src/views/activity/activity_model.js b/addons/mail/static/src/views/activity/activity_model.js index 251320b423e..dcae18f6ea8 100644 --- a/addons/mail/static/src/views/activity/activity_model.js +++ b/addons/mail/static/src/views/activity/activity_model.js @@ -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); } diff --git a/addons/test_mail/static/tests/activity_tests.js b/addons/test_mail/static/tests/activity_tests.js index 999bc6e9bad..dd73588b847 100644 --- a/addons/test_mail/static/tests/activity_tests.js +++ b/addons/test_mail/static/tests/activity_tests.js @@ -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) {