diff options
| author | Nikunj Ladava <nla@odoo.com> | 2018-01-31 16:51:13 +0530 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-02-15 17:25:00 +0100 |
| commit | 4c186f30c3a77e661f0dfdd39fe2c1216ef1ac7b (patch) | |
| tree | a3e0455cbf90f257f6ea7a74b5309bfc0402f583 | |
| parent | 8b9e854be4bfe3eda9a15368a864f7af606dee31 (diff) | |
[FIX] web: ActionManager: handle false actions
Server actions return an action to execute, or false. When they
return false, an 'ir.actions.act_window_close' must be executed,
such that the current dialog closes (if any) and mostly, the
'on_close' handler is executed, which ensures for example that the
current view is reloaded.
The case where server actions return false has been broken by rev.
32b8cec53. It produced tracebacks in several models, when clicking
on some actions in the 'Action' dropdown. For instance, in lunch,
go to Configuration > Products, open one in a form view, and click
on 'Lunch: Archive/Restore products' in the Action dropdown.
| -rw-r--r-- | addons/web/static/src/js/chrome/action_manager.js | 1 | ||||
| -rw-r--r-- | addons/web/static/tests/chrome/action_manager_tests.js | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index 237ce1f1c96..1651e5d72d9 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -510,6 +510,7 @@ var ActionManager = Widget.extend({ }, }); return this.dp.add(runDef).then(function (action) { + action = action || { type: 'ir.actions.act_window_close' }; return self.doAction(action, options); }); }, diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 6c580e6b9dc..c85e8a8c42c 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -1324,6 +1324,45 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('handle server actions returning false', function (assert) { + assert.expect(9); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + mockRPC: function (route, args) { + assert.step(args.method || route); + if (route === '/web/action/run') { + return $.when(false); + } + return this._super.apply(this, arguments); + }, + }); + + // execute an action in target="new" + actionManager.doAction(5, { + on_close: assert.step.bind(assert, 'close handler'), + }); + assert.strictEqual($('.o_technical_modal .o_form_view').length, 1, + "should have rendered a form view in a modal"); + + // execute a server action that returns false + actionManager.doAction(2); + assert.strictEqual($('.o_technical_modal').length, 0, + "should have closed the modal"); + assert.verifySteps([ + '/web/action/load', // action 5 + 'load_views', + 'default_get', + '/web/action/load', // action 2 + '/web/action/run', + 'close handler', + ]); + + actionManager.destroy(); + }); + QUnit.module('Report actions'); QUnit.test('can execute report actions from db ID', function (assert) { |
