From a39cc6bc00df1a72cb12cfaa9c56cbe9fafaee83 Mon Sep 17 00:00:00 2001 From: aab-odoo Date: Mon, 24 Feb 2020 10:17:15 +0000 Subject: [PATCH] [FIX] web: grouped list with pager: reset offset on search Have a grouped list view with enough groups to have several pages. Go to the second page, and toggle a filter s.t. it only remains a single page of groups. Before this commit, no group is displayed (like if there was no record matching the domain), whereas it should display groups of page 1. The issue occurs because we didn't reset the group offset to 0, like we do for the regular offset. Bug reported in the v13 migration pad. closes odoo/odoo#46257 X-original-commit: c6a4123b25e884495c5c44287d4d9fed061eeaa4 Signed-off-by: Aaron Bohy (aab) --- .../src/js/views/abstract_controller.js | 2 +- addons/web/static/tests/views/list_tests.js | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js index a0152e5ccc4..aa612cbea01 100644 --- a/addons/web/static/src/js/views/abstract_controller.js +++ b/addons/web/static/src/js/views/abstract_controller.js @@ -618,7 +618,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, WidgetAdapterMixin, */ _onSearch: function (ev) { ev.stopPropagation(); - this.reload(_.extend({offset: 0}, ev.data)); + this.reload(_.extend({offset: 0, groupsOffset: 0}, ev.data)); }, /** * @private diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 6e2297be1c2..1ff480fb0e1 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -6960,6 +6960,64 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('add filter in a grouped list with a pager', async function (assert) { + assert.expect(11); + + const actionManager = await createActionManager({ + data: this.data, + actions: [{ + id: 11, + name: 'Action 11', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [9, 'search'], + flags: { + context: { group_by: ['int_field'] }, + }, + }], + archs: { + 'foo,3,list': '', + 'foo,9,search': ` + + + `, + }, + mockRPC: function (route, args) { + if (args.method === 'web_read_group') { + assert.step(JSON.stringify(args.kwargs.domain) + ', ' + args.kwargs.offset); + } + return this._super.apply(this, arguments); + }, + }); + + await actionManager.doAction(11); + + assert.containsOnce(actionManager, '.o_list_view'); + assert.strictEqual(actionManager.$('.o_pager_counter').text().trim(), '1-3 / 4'); + assert.containsN(actionManager, '.o_group_header', 3); // page 1 + + await testUtils.dom.click(actionManager.$('.o_pager_next')); // switch to page 2 + + assert.strictEqual(actionManager.$('.o_pager_counter').text().trim(), '4-4 / 4'); + assert.containsN(actionManager, '.o_group_header', 1); // page 2 + + // toggle a filter -> there should be only one group left (on page 1) + await testUtils.dom.click(actionManager.$('.o_control_panel .o_search_options .o_filters_menu_button')); + await testUtils.dom.click(actionManager.$('.o_control_panel .o_search_options .o_filters_menu .o_menu_item:first')); + + assert.strictEqual(actionManager.$('.o_pager_counter').text().trim(), '1-1 / 1'); + assert.containsN(actionManager, '.o_group_header', 1); // page 1 + + assert.verifySteps([ + '[], undefined', + '[], 3', + '[["bar","=",false]], undefined', + ]); + + actionManager.destroy(); + }); + QUnit.test('editable grouped lists', async function (assert) { assert.expect(4);