[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) <jum@odoo.com>
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
This commit is contained in:
Simon Genin (ges)
2022-09-27 17:11:48 +02:00
parent 954e690edd
commit a105e8b3cb
2 changed files with 18 additions and 2 deletions
@@ -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();
@@ -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: '<tree groups_limit="1"><field name="foo"/><field name="bar"/></tree>',
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]);
});
});