diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index b36e1b8eec9..c7e9827cdf9 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -768,17 +768,17 @@ var ActionManager = Widget.extend({ * @param {Object} options see @doAction options */ _preprocessAction: function (action, options) { - action._originalAction = JSON.stringify(action); - - action.jsID = _.uniqueId('action_'); - action.pushState = options.pushState; - // ensure that the context and domain are evaluated var context = new Context(this.userContext, options.additional_context, action.context); action.context = pyeval.eval('context', context); if (action.domain) { action.domain = pyeval.eval('domain', action.domain, action.context); } + + action._originalAction = JSON.stringify(action); + + action.jsID = _.uniqueId('action_'); + action.pushState = options.pushState; }, /** * Unlinks the given action and its controller from the internal structures diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index bf8ba59f205..0ba4764dfc8 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -12,6 +12,7 @@ var ListController = require('web.ListController'); var StandaloneFieldManagerMixin = require('web.StandaloneFieldManagerMixin'); var RamStorage = require('web.RamStorage'); var ReportService = require('web.ReportService'); +var SessionStorageService = require('web.SessionStorageService'); var testUtils = require('web.test_utils'); var Widget = require('web.Widget'); var createActionManager = testUtils.createActionManager; @@ -2859,6 +2860,68 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test("current act_window action is stored in session_storage", function (assert) { + assert.expect(1); + + var expectedAction = _.extend({}, _.findWhere(this.actions, {id: 3}), { + context: {}, + }); + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + services: [SessionStorageService.extend({ + setItem: function (key, value) { + assert.strictEqual(value, JSON.stringify(expectedAction), + "should store the executed action in the sessionStorage"); + }, + })], + }); + + actionManager.doAction(3); + + actionManager.destroy(); + }); + + QUnit.test("store evaluated context of current action in session_storage", function (assert) { + // this test ensures that we don't store stringified instances of + // CompoundContext in the session_storage, as they would be meaningless + // once restored + assert.expect(1); + + var expectedAction = _.extend({}, _.findWhere(this.actions, {id: 4}), { + context: { + active_model: 'partner', + active_id: 1, + active_ids: [1], + }, + }); + var checkSessionStorage = false; + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + services: [SessionStorageService.extend({ + setItem: function (key, value) { + if (checkSessionStorage) { + assert.strictEqual(value, JSON.stringify(expectedAction), + "should correctly store the executed action in the sessionStorage"); + } + }, + })], + }); + + // execute an action and open a record in form view + actionManager.doAction(3); + actionManager.$('.o_list_view .o_data_row:first').click(); + + // click on 'Execute action' button (it executes an action with a CompoundContext as context) + checkSessionStorage = true; + actionManager.$('.o_form_view button:contains(Execute action)').click(); + + actionManager.destroy(); + }); + QUnit.module('Actions in target="new"'); QUnit.test('can execute act_window actions in target="new"', function (assert) {