diff --git a/addons/board/static/src/js/favorite_menu.js b/addons/board/static/src/js/favorite_menu.js index 77cd3df4967..701ebef2801 100644 --- a/addons/board/static/src/js/favorite_menu.js +++ b/addons/board/static/src/js/favorite_menu.js @@ -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, diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index 1211fc5da05..9afb88e5648 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -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': '', + 'partner,false,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': '', + 'partner,false,list': '', + 'partner,false,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(); +}); + });