[FIX] web: ActionManager: store evaluated context
... in session_storage. The current action is stored in the session_storage (stringified), so that it can always be restored on F5 (useful for dynamic actions). Before this rev., it was stored with it's 'raw' context, i.e. before its evaluation. However, when this context is an instance of a CompoundContext, it is meaningless once restored. So this rev. ensures that the action is stored with its evaluated context.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user