[FIX] web: update domain when switching between views

Let's assume the following scenario on an action with two multi
records views (e.g. kanban and list). In the kanban view, activate
a domain or groupby, switch to list view, remove the domain or
groupby, switch back to kanban: the domain or groupby is still
applied (even though it's no longer displayed in the search view).

This is due to the jQuery update (ab56e637b7) and the use of
native Promises (always async) instead of old jQuery 1.11 Deferreds
(which where sync when already resolved). In the new version, the
domain/context/groupby were added to the params a 'tick too late',
so the view was updated without that information (and thus the old
domain/context/groupby were kept).

Issue reported on the jquery update pad.

closes odoo/odoo#31859

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
This commit is contained in:
Aaron Bohy
2019-03-15 07:35:21 +00:00
parent b9da175574
commit 9a8f59a674
2 changed files with 39 additions and 2 deletions
@@ -182,6 +182,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
*/
reload: function (params) {
params = params || {};
var self = this;
var def;
var controllerState = params.controllerState || {};
var cpState = controllerState.cpState;
@@ -190,7 +191,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
params = _.extend({}, params, searchQuery);
});
}
return Promise.resolve(def).then(this.update.bind(this, params, {}));
return Promise.resolve(def).then(function () {
return self.update(params, {});
});
},
/**
* For views that require a pager, this method will be called to allow the
@@ -2208,7 +2208,7 @@ QUnit.module('ActionManager', {
QUnit.test('orderedBy in context is not propagated when executing another action', async function (assert) {
assert.expect(6);
this.data.partner.fields.foo.sortable = true,
this.data.partner.fields.foo.sortable = true;
this.archs['partner,false,form'] = '<header>' +
'<button name="8" string="Execute action" type="action"/>' +
@@ -2422,6 +2422,40 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
QUnit.test("domain is kept when switching between views", async function (assert) {
assert.expect(5);
this.actions[2].search_view_id = [1, 'a custom search view'];
var actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(3);
assert.containsN(actionManager, '.o_data_row', 5);
// activate a domain
await testUtils.dom.click(actionManager.$('.o_search_options .o_filters_menu_button'));
await testUtils.dom.click(actionManager.$('.o_search_options .o_filters_menu a:contains(Bar)'));
assert.containsN(actionManager, '.o_data_row', 2);
// switch to kanban
await testUtils.dom.click(actionManager.$('.o_control_panel .o_cp_switch_kanban'));
assert.containsN(actionManager, '.o_kanban_record:not(.o_kanban_ghost)', 2);
// remove the domain
await testUtils.dom.click(actionManager.$('.o_searchview .o_facet_remove'));
assert.containsN(actionManager, '.o_kanban_record:not(.o_kanban_ghost)', 5);
// switch back to list
await testUtils.dom.click(actionManager.$('.o_control_panel .o_cp_switch_list'));
assert.containsN(actionManager, '.o_data_row', 5);
actionManager.destroy();
});
QUnit.test('there is no flickering when switching between views', async function (assert) {
assert.expect(20);