diff --git a/addons/web/static/src/views/widgets/attach_document/attach_document.js b/addons/web/static/src/views/widgets/attach_document/attach_document.js index 7ce0b9ca480..975ee5d83df 100644 --- a/addons/web/static/src/views/widgets/attach_document/attach_document.js +++ b/addons/web/static/src/views/widgets/attach_document/attach_document.js @@ -14,12 +14,13 @@ class AttachDocumentWidget extends Component { } async onFileUploaded(files) { - const { action } = this.props; + const { action, record } = this.props; if (action) { - const { model, resId, resModel } = this.props.record; + const { model, resId, resModel } = record; await this.orm.call(resModel, action, [resId], { attachment_ids: files.map((file) => file.id), }); + await record.load(); model.notify(); } } diff --git a/addons/web/static/tests/views/widgets/attach_document_tests.js b/addons/web/static/tests/views/widgets/attach_document_tests.js index c76eb9a9d34..892e8df4741 100644 --- a/addons/web/static/tests/views/widgets/attach_document_tests.js +++ b/addons/web/static/tests/views/widgets/attach_document_tests.js @@ -53,17 +53,19 @@ QUnit.module("Widgets", (hooks) => { serverData, resId: 1, mockRPC(route, args) { + assert.step(args.method); if (args.method === "my_action") { - assert.step("my_action"); assert.deepEqual(args.model, "partner"); assert.deepEqual(args.args, [1]); assert.deepEqual(args.kwargs.attachment_ids, [5, 2]); return true; } if (args.method === "write") { - assert.step("write"); assert.deepEqual(args.args[1], { display_name: "yop" }); } + if (args.method === "read") { + assert.deepEqual(args.args[0], [1]); + } }, arch: `
`, }); + assert.verifySteps(["get_views", "read"]); await editInput(target, "[name='display_name'] input", "yop"); await click(target, ".o_attach_document"); @@ -81,6 +84,61 @@ QUnit.module("Widgets", (hooks) => { {}, { skipVisibilityCheck: true } ); - assert.verifySteps(["write", "post", "my_action"]); + assert.verifySteps(["write", "read", "post", "my_action", "read"]); }); + + QUnit.test( + "attach document widget calls action with attachment ids on a new record", + async function (assert) { + serviceRegistry.add("http", { + start: () => ({ + post: (route, params) => { + assert.step("post"); + assert.strictEqual(route, "/web/binary/upload_attachment"); + assert.strictEqual(params.model, "partner"); + assert.strictEqual(params.id, 2); + return '[{ "id": 5 }, { "id": 2 }]'; + }, + }), + }); + + await makeView({ + type: "form", + resModel: "partner", + serverData, + mockRPC(route, args) { + assert.step(args.method); + if (args.method === "my_action") { + assert.deepEqual(args.model, "partner"); + assert.deepEqual(args.args, [2]); + assert.deepEqual(args.kwargs.attachment_ids, [5, 2]); + return true; + } + if (args.method === "create") { + assert.deepEqual(args.args[0], { display_name: "yop" }); + } + if (args.method === "read") { + assert.deepEqual(args.args[0], [2]); + } + }, + arch: ` + `, + }); + assert.verifySteps(["get_views", "onchange"]); + + await editInput(target, "[name='display_name'] input", "yop"); + await click(target, ".o_attach_document"); + await triggerEvent( + target, + ".o_file_input input", + "change", + {}, + { skipVisibilityCheck: true } + ); + assert.verifySteps(["create", "read", "post", "my_action", "read"]); + } + ); });