diff --git a/addons/web/static/src/js/core/mixins.js b/addons/web/static/src/js/core/mixins.js index fff2a013bb5..9c643597f04 100644 --- a/addons/web/static/src/js/core/mixins.js +++ b/addons/web/static/src/js/core/mixins.js @@ -495,19 +495,23 @@ var ServicesMixin = { return session; }, /** - * Informs the action manager to do an action. This supposes that - * the action manager can be found amongst the ancestors of the current widget. - * If that's not the case this method will simply return `false`. + * Informs the action manager to do an action. This supposes that the action + * manager can be found amongst the ancestors of the current widget. + * If that's not the case this method will simply return an unresolved + * deferred. + * + * @param {any} action + * @param {any} options + * @returns {Deferred} */ do_action: function (action, options) { var def = $.Deferred(); - options = options || {}; - var oldOnSuccess = options.on_success; - options.on_success = function (result) { - oldOnSuccess(result); - def.resolve(result); - }; - this.trigger_up('do_action', {'action': action, options: options}); + + this.trigger_up('do_action', { + action: action, + options: options, + on_success: function (result) { def.resolve(result); }, + }); return def; }, do_notify: function (title, message, sticky, className) { diff --git a/addons/web/static/tests/core/mixins_tests.js b/addons/web/static/tests/core/mixins_tests.js new file mode 100644 index 00000000000..c49c33ec648 --- /dev/null +++ b/addons/web/static/tests/core/mixins_tests.js @@ -0,0 +1,34 @@ +odoo.define('web.mixins_tests', function (require) { +"use strict"; + +var testUtils = require('web.test_utils'); +var Widget = require('web.Widget'); + +QUnit.module('core', {}, function () { + + QUnit.module('mixins'); + + QUnit.test('perform a do_action properly', function (assert) { + assert.expect(3); + + var widget = new Widget(); + + testUtils.intercept(widget, 'do_action', function (event) { + assert.strictEqual(event.data.action, 'test.some_action_id', + "should have sent proper action name"); + assert.deepEqual(event.data.options, {clear_breadcrumbs: true}, + "should have sent proper options"); + event.data.on_success(); + }); + + widget.do_action('test.some_action_id', {clear_breadcrumbs: true}).then(function () { + assert.step('deferred should have been resolved'); + }); + widget.destroy(); + }); + + +}); + +}); + diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index 27831759b4b..e5789e9e7aa 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -450,6 +450,7 @@ +