From cd00f242c79ee50bb0ec4fbc25f6e2626c7ac52c Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 17 Jan 2023 07:36:48 +0000 Subject: [PATCH] [FIX] web: list/kanban: remove count limit if total clicked Commit [1] adds a limit on the search_count done to get the total number of records matching the domain in a list or kanban view (displayed in the pager). When the limit is reached (10000), a `10000+` is displayed as total. Clicking on it performs a search_count to get the actual number of records. Before this commit, from that point, the count limit was set to the total number of records. It means that if a record was created or modified to match the domain in the meantime, and the user clicked on the pager to see the next page (for instance), a `+` was again displayed next to the previously fetched search_count, which looks like a bug. To prevent this from happening, this commit simply removes the count limit once the user has clicked on the total. [1] 6acfad26513298f57a2edcf40d0f7a2e38a97295 closes odoo/odoo#110348 X-original-commit: 9aab36bcfb682865b615c8fbbc107afeee3a24f4 Related: odoo/enterprise#36001 Signed-off-by: Jorge Pinna Puissant (jpp) --- addons/web/static/src/views/relational_model.js | 6 ++++-- addons/web/static/tests/views/list_view_tests.js | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/relational_model.js b/addons/web/static/src/views/relational_model.js index 143623c5d93..355e302e0ec 100644 --- a/addons/web/static/src/views/relational_model.js +++ b/addons/web/static/src/views/relational_model.js @@ -2016,7 +2016,7 @@ export class DynamicRecordList extends DynamicList { async fetchCount() { const keepLast = this.model.keepLast; this.count = await keepLast.add(this.model.orm.searchCount(this.resModel, this.domain)); - this.countLimit = this.count; + this.countLimit = Number.MAX_SAFE_INTEGER; this.hasLimitedCount = false; this.model.notify(); } @@ -2101,12 +2101,14 @@ export class DynamicRecordList extends DynamicList { limit: this.limit, offset: this.offset, order: orderByToString(this.orderBy), - count_limit: this.countLimit + 1, context: { bin_size: true, ...this.context, }, }; + if (this.countLimit !== Number.MAX_SAFE_INTEGER) { + kwargs.count_limit = this.countLimit + 1; + } const { records: rawRecords, length } = this.data || (await this.model.orm.webSearchRead( diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 0baebd5412e..144212cf0fc 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -5654,6 +5654,7 @@ QUnit.module("Views", (hooks) => { QUnit.test("pager, ungrouped, with count limit reached", async function (assert) { patchWithCleanup(DynamicRecordList, { WEB_SEARCH_READ_COUNT_LIMIT: 3 }); + let expectedCountLimit = 4; await makeView({ type: "list", resModel: "foo", @@ -5661,6 +5662,9 @@ QUnit.module("Views", (hooks) => { arch: '', mockRPC(route, args) { assert.step(args.method); + if (args.method === "web_search_read") { + assert.strictEqual(args.kwargs.count_limit, expectedCountLimit); + } }, }); @@ -5674,6 +5678,10 @@ QUnit.module("Views", (hooks) => { assert.strictEqual(target.querySelector(".o_pager_value").innerText, "1-2"); assert.strictEqual(target.querySelector(".o_pager_limit").innerText, "4"); assert.verifySteps(["search_count"]); + + expectedCountLimit = undefined; + await click(target.querySelector(".o_pager_next")); + assert.verifySteps(["web_search_read"]); }); QUnit.test("pager, ungrouped, with count equals count limit", async function (assert) {