From a105e8b3cb3e7c5aaf758671c07f75177bdc4e94 Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Mon, 26 Sep 2022 14:50:58 +0000 Subject: [PATCH] [FIX] web: pager offset in list interprets 0 as falsy when it shouldn't If a view with groups and pager, going next then previous (back to the 0 offset) doesn't work. The pager offset and limit were used in an conditional expression. If the value was 0, it was considered falsy and set to a default value while the 0 was actually a valid and expected value. closes odoo/odoo#101314 X-original-commit: 5c9173241dbe55007c3a84fe078d21ea733e9046 Signed-off-by: Julien Mougenot (jum) Signed-off-by: Simon Genin (ges@odoo) --- addons/web/static/src/views/relational_model.js | 4 ++-- addons/web/static/tests/views/list_view_tests.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/relational_model.js b/addons/web/static/src/views/relational_model.js index 4ced79c2dff..6f67c5bf67b 100644 --- a/addons/web/static/src/views/relational_model.js +++ b/addons/web/static/src/views/relational_model.js @@ -2223,8 +2223,8 @@ export class DynamicGroupList extends DynamicList { } async load(params = {}) { - this.limit = params.limit || this.limit; - this.offset = params.offset || this.offset; + this.limit = params.limit === undefined ? this.limit : params.limit; + this.offset = params.offset === undefined ? this.offset : params.offset; /** @type {[Group, number][]} */ const previousGroups = this.groups.map((g, i) => [g, i]); this.groups = await this._loadGroups(); diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index f40c7ed87a6..aaa5f421f0d 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -15045,4 +15045,20 @@ QUnit.module("Views", (hooks) => { assert.containsN(target, ".o_data_row:first-child td.o_list_button", 1); await click(target, ".o_data_row:first-child td.o_list_button"); }); + + QUnit.test("group by going to next page then back to first", async function (assert) { + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: '', + groupBy: ["bar"], + }); + + assert.deepEqual([...getPagerValue(target), getPagerLimit(target)], [1, 2]); + await pagerNext(target); + assert.deepEqual([...getPagerValue(target), getPagerLimit(target)], [2, 2]); + await pagerPrevious(target); + assert.deepEqual([...getPagerValue(target), getPagerLimit(target)], [1, 2]); + }); });