From 6c881fda0433341d6b8e1da07ab2cde65ae00295 Mon Sep 17 00:00:00 2001 From: fdardenne Date: Fri, 5 May 2023 07:33:47 +0000 Subject: [PATCH] [FIX] mail: activity view: fix the records limit The activity view is an aggregation view, meaning that we show all the activies with no limit of records. Steps to reproduce: There is no easy way to reproduce the bug, the database should be populated with more than 80 records in a model and have an activity planned for the 81th record. Current Behaviour: The Activity view loads all the activities without limit and so the activity for the 81th record. The problem is that the 81th record does not have been loaded due to the default limit of the RelationaLModel. Therefore the activity view crash because it cannot fetch the missing record for a loaded activity. Expected Behaviour: The activity view laods all the activities but also loads all the records so it can render them. closes odoo/odoo#120654 X-original-commit: 885c7bb33a3cb25962c090290e6b27bc11a71f41 Signed-off-by: Luca Vitali Signed-off-by: Dardenne Florent (dafl) --- .../src/views/activity/activity_model.js | 10 ++++- .../test_mail/static/tests/activity_tests.js | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/views/activity/activity_model.js b/addons/mail/static/src/views/activity/activity_model.js index 6caee2ece6e..251320b423e 100644 --- a/addons/mail/static/src/views/activity/activity_model.js +++ b/addons/mail/static/src/views/activity/activity_model.js @@ -1,8 +1,16 @@ /** @odoo-module */ -import { RelationalModel } from "@web/views/relational_model"; +import { DynamicRecordList, RelationalModel } from "@web/views/relational_model"; +class ActivityDynamicRecordList extends DynamicRecordList { + setup() { + super.setup(...arguments); + this.limit = null; + } +} export class ActivityModel extends RelationalModel { + static DynamicRecordList = ActivityDynamicRecordList; + async load(params = {}) { this.originalDomain = params.domain ? [...params.domain] : []; params.domain?.push(["activity_ids", "!=", false]); diff --git a/addons/test_mail/static/tests/activity_tests.js b/addons/test_mail/static/tests/activity_tests.js index 05392c68139..017b8884904 100644 --- a/addons/test_mail/static/tests/activity_tests.js +++ b/addons/test_mail/static/tests/activity_tests.js @@ -205,6 +205,47 @@ QUnit.module("test_mail", {}, function () { ); }); + QUnit.test( + "activity view: there is no default limit of 80 in the relationalModel", + async function (assert) { + const mailActivityTypeIds = pyEnv["mail.activity.type"].search([]); + + const recordsToCreate = []; + const activityToCreate = []; + + for (let i = 0; i < 81; i++) { + activityToCreate.push({ + display_name: "An activity " + i, + date_deadline: moment().add(3, "days").format("YYYY-MM-DD"), // now + can_write: true, + state: "planned", + activity_type_id: mailActivityTypeIds[0], + }); + } + const createdActivity = pyEnv["mail.activity"].create(activityToCreate); + for (let i = 0; i < 81; i++) { + // The default limit of the RelationalModel is 80, test if it is overwrited by creating more than 80 records + recordsToCreate.push({ name: i + "", activity_ids: [createdActivity[i]] }); + } + pyEnv["mail.test.activity"].create(recordsToCreate); + + const { openView } = await start({ + serverData, + }); + await openView({ + res_model: "mail.test.activity", + views: [[false, "activity"]], + }); + + const activityRecords = document.querySelectorAll(".o_activity_record"); + assert.strictEqual( + activityRecords.length, + 83, + "The 83 records should have been loaded" + ); + } + ); + QUnit.test("activity view: no content rendering", async function (assert) { assert.expect(2);