[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 <luvi@odoo.com>
Signed-off-by: Dardenne Florent (dafl) <dafl@odoo.com>
This commit is contained in:
fdardenne
2023-05-05 13:52:34 +02:00
parent 78b275f54d
commit 6c881fda04
2 changed files with 50 additions and 1 deletions
@@ -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]);
@@ -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);