diff --git a/addons/web/static/src/js/widgets/attach_document.js b/addons/web/static/src/js/widgets/attach_document.js index 3175875c151..a4a72a62765 100644 --- a/addons/web/static/src/js/widgets/attach_document.js +++ b/addons/web/static/src/js/widgets/attach_document.js @@ -109,10 +109,10 @@ var AttachDocument = Widget.extend({ */ _onFileLoaded: function () { var self = this; + // the first argument isn't a file but the jQuery.Event + var files = Array.prototype.slice.call(arguments, 1); return new Promise(function (resolve) { if (self.node.attrs.action) { - // the first argument isn't a file but the jQuery.Event - var files = Array.prototype.slice.call(arguments, 1); self._rpc({ model: self.res_model, method: self.node.attrs.action, diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index c01a1c46fb3..f41dbcb7f28 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -6801,6 +6801,32 @@ QUnit.module('Views', { delete widgetRegistry.map.test; }); + QUnit.test('attach document widget calls action with attachment ids', async function (assert) { + assert.expect(1); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + mockRPC: function (route, args) { + if (args.method === 'my_action') { + assert.deepEqual(args.kwargs.attachment_ids, [5, 2]); + return Promise.resolve(); + } + return this._super.apply(this, arguments); + }, + arch: '
', + }); + + var onFileLoadedEventName = form.$('.o_form_binary_form').attr('target') + // trigger _onFileLoaded function + $(window).trigger(onFileLoadedEventName, [{id: 5}, {id:2}]); + + form.destroy(); + }); + QUnit.test('support header button as widgets on form statusbar', async function (assert) { assert.expect(2);