[FIX] board: action executed with option keepSearchView

Rev. 69c9500e recently added option 'keepSearchView' to doAction in
the ActionManager. When set to true, the searchview of the current
action is re-used by the executed action.

This caused issues with the dashboard, as the wrong action id was
used to save the current action to the dashboard (it was the one
of the action for which the searchview was instantiated, not the
one of the current action, executed with option keepSearchView set
to true). For instance, go to Website (in enterprise), in the
new dashboard (view) expand the graph view, try to add the graph
action to the dashboard (board).

Task 1835670.
This commit is contained in:
Aaron Bohy
2018-04-27 13:40:35 +02:00
parent 25c5c62623
commit 3628014abd
2 changed files with 95 additions and 1 deletions
+5 -1
View File
@@ -71,6 +71,10 @@ FavoriteMenu.include({
var am = this.findAncestor(function (a) {
return a instanceof ActionManager;
});
// with options 'keepSearchView', it may happen that the action_id of
// the searchview (received in init) is not the one of the current
// action, which corresponds to the one we want to add to dashboard
var currentAction = am.getCurrentAction();
var controller = am.getCurrentController();
context.add(controller.widget.getContext());
var c = pyeval.eval('context', context);
@@ -86,7 +90,7 @@ FavoriteMenu.include({
return self._rpc({
route: '/board/add_to_dashboard',
params: {
action_id: self.action_id || false,
action_id: currentAction.id || false,
context_to_save: c,
domain: domain,
view_mode: controller.viewType,
@@ -7,6 +7,7 @@ var ListController = require('web.ListController');
var testUtils = require('web.test_utils');
var ListRenderer = require('web.ListRenderer');
var createActionManager = testUtils.createActionManager;
var createView = testUtils.createView;
QUnit.module('Dashboard', {
@@ -556,4 +557,93 @@ QUnit.test('dashboard intercepts custom events triggered by sub controllers', fu
board.destroy();
});
QUnit.test('save actions to dashboard', function (assert) {
assert.expect(4);
var actionManager = createActionManager({
data: this.data,
archs: {
'partner,false,list': '<list><field name="foo"/></list>',
'partner,false,search': '<search></search>',
},
mockRPC: function (route, args) {
if (route === '/board/add_to_dashboard') {
assert.strictEqual(args.action_id, 1,
"should save the correct action");
assert.strictEqual(args.view_mode, 'list',
"should save the correct view type");
return $.when(true);
}
return this._super.apply(this, arguments);
},
});
actionManager.doAction({
id: 1,
res_model: 'partner',
type: 'ir.actions.act_window',
views: [[false, 'list']],
});
assert.strictEqual(actionManager.$('.o_list_view').length, 1,
"should display the list view");
assert.strictEqual($('.o_add_to_dashboard_link').length, 1,
"should allow the 'Add to dashboard' feature");
// add this action to dashboard
$('.o_add_to_dashboard_button').click();
actionManager.destroy();
});
QUnit.test('save to dashboard actions with flag keepSearchView', function (assert) {
assert.expect(4);
var actionManager = createActionManager({
data: this.data,
archs: {
'partner,false,graph': '<graph><field name="foo"/></graph>',
'partner,false,list': '<list><field name="foo"/></list>',
'partner,false,search': '<search></search>',
},
mockRPC: function (route, args) {
if (route === '/board/add_to_dashboard') {
assert.strictEqual(args.action_id, 2,
"should save the correct action");
assert.strictEqual(args.view_mode, 'graph',
"should save the correct view type");
return $.when(true);
}
return this._super.apply(this, arguments);
},
});
// execute a first action
actionManager.doAction({
id: 1,
res_model: 'partner',
type: 'ir.actions.act_window',
views: [[false, 'list']],
});
// execute another action with flag 'keepSearchView' and add it to dashboard
var options = {keepSearchView: true};
actionManager.doAction({
id: 2,
res_model: 'partner',
type: 'ir.actions.act_window',
views: [[false, 'graph']],
}, options);
assert.strictEqual(actionManager.$('.o_graph').length, 1,
"should display the graph view");
assert.strictEqual($('.o_add_to_dashboard_link').length, 1,
"should allow the 'Add to dashboard' feature (this is the same searchview)");
// add this action to dashboard
$('.o_add_to_dashboard_button').click();
actionManager.destroy();
});
});