diff --git a/addons/web/static/src/js/chrome/action_manager_act_window.js b/addons/web/static/src/js/chrome/action_manager_act_window.js
index f505cccadfe..bff130f5b63 100644
--- a/addons/web/static/src/js/chrome/action_manager_act_window.js
+++ b/addons/web/static/src/js/chrome/action_manager_act_window.js
@@ -121,6 +121,22 @@ ActionManager.include({
* @returns {Deferred} resolved with the search view when it is ready
*/
_createSearchView: function (action) {
+ // if requested, keep the searchview of the current action instead of
+ // creating a new one
+ if (action._keepSearchView) {
+ var currentAction = this.getCurrentAction();
+ if (currentAction) {
+ action.searchView = currentAction.searchView;
+ action.env = currentAction.env; // make those actions share the same env
+ return $.when(currentAction.searchView);
+ } else {
+ // there is not searchview to keep, so reset the flag to false
+ // to ensure that the one that will be created will be correctly
+ // destroyed
+ action._keepSearchView = false;
+ }
+ }
+
// AAB: temporarily create a dataset, until the SearchView is refactored
// and stops using it
var dataset = new data.DataSetSearch(this, action.res_model, action.context, action.domain);
@@ -254,7 +270,7 @@ ActionManager.include({
// its reference is removed
controllerDef.reject();
});
- if (action.searchView) {
+ if (action.searchView && !action._keepSearchView) {
action.searchView.destroy();
}
},
@@ -483,6 +499,20 @@ ActionManager.include({
}
return this.loadViews(action.res_model, action.context, views, options);
},
+ /**
+ * Overrides to handle the 'keepSearchView' option. If set to true, the
+ * search view of the current action will be re-used in the new action, i.e.
+ * the environment (domain, context, groupby) will be shared between both
+ * actions.
+ *
+ * @override
+ */
+ _preprocessAction: function (action, options) {
+ this._super.apply(this, arguments);
+ if (action.type === 'ir.actions.act_window' && options.keepSearchView) {
+ action._keepSearchView = true;
+ }
+ },
/**
* Processes the search data sent by the search view.
*
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js
index 5859f16ca36..ff8fe80a523 100644
--- a/addons/web/static/tests/chrome/action_manager_tests.js
+++ b/addons/web/static/tests/chrome/action_manager_tests.js
@@ -126,6 +126,9 @@ QUnit.module('ActionManager', {
// search views
'partner,false,search': '',
+ 'partner,1,search': '' +
+ '' +
+ '',
'pony,false,search': '',
};
},
@@ -2714,13 +2717,6 @@ QUnit.module('ActionManager', {
},
});
- _.extend(this.archs, {
- 'partner,7,search':
- '' +
- '' +
- '',
- });
-
this.actions.push({
id: 33,
context: {
@@ -2728,7 +2724,7 @@ QUnit.module('ActionManager', {
},
name: 'Partners',
res_model: 'partner',
- search_view_id: [7, 'a custom search view'],
+ search_view_id: [1, 'a custom search view'],
type: 'ir.actions.act_window',
views: [[false, 'list']],
});
@@ -2792,6 +2788,46 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
+ QUnit.test("doAction with option 'keepSearchView'", function (assert) {
+ assert.expect(4);
+
+ this.actions.push({
+ id: 33,
+ name: 'Partners',
+ res_model: 'partner',
+ search_view_id: [1, 'a specific search view'],
+ type: 'ir.actions.act_window',
+ views: [[false, 'list']],
+ });
+
+ var checkRPC = false;
+ var actionManager = createActionManager({
+ actions: this.actions,
+ archs: this.archs,
+ data: this.data,
+ mockRPC: function (route, args) {
+ if (checkRPC && route === '/web/dataset/search_read') {
+ assert.deepEqual(args.domain, [['bar', '=', 1]],
+ "should search with the correct domain");
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ actionManager.doAction(33);
+
+ checkRPC = true;
+ $('.o_control_panel .o_filters_menu a:contains(Bar)').click(); // filter on bar
+ assert.strictEqual($('.o_control_panel .o_facet_values').text().trim(), 'Bar',
+ "the filter on Bar should appear in the search view");
+
+ actionManager.doAction(3, {keepSearchView: true});
+ assert.strictEqual($('.o_control_panel .o_facet_values').text().trim(), 'Bar',
+ "the filter on Bar should still be in the search view");
+
+ actionManager.destroy();
+ });
+
QUnit.module('Actions in target="new"');
QUnit.test('can execute act_window actions in target="new"', function (assert) {