diff --git a/addons/mail/static/src/core/web/chatter.js b/addons/mail/static/src/core/web/chatter.js index 7e2f008bb3e..5c09a534049 100644 --- a/addons/mail/static/src/core/web/chatter.js +++ b/addons/mail/static/src/core/web/chatter.js @@ -131,7 +131,11 @@ export class Chatter extends Component { return; } } - files.forEach((file) => this.attachmentUploader.uploadFile(file)); + Promise.all(files.map((file) => this.attachmentUploader.uploadFile(file))).then(() => { + if (this.props.hasParentReloadOnAttachmentsChanged) { + this.reloadParentView(); + } + }) this.state.isAttachmentBoxOpened = true; } }, diff --git a/addons/mail/static/tests/helpers/model_definitions_setup.js b/addons/mail/static/tests/helpers/model_definitions_setup.js index 5d236065437..78ea64c8191 100644 --- a/addons/mail/static/tests/helpers/model_definitions_setup.js +++ b/addons/mail/static/tests/helpers/model_definitions_setup.js @@ -115,6 +115,16 @@ insertModelFields("res.users.settings", { is_discuss_sidebar_category_channel_open: { default: true }, is_discuss_sidebar_category_chat_open: { default: true }, }); +insertModelFields("res.partner", { + message_main_attachment_id: { + name: "message_main_attachment_id", + readonly: false, + relation: "ir.attachment", + required: false, + string: "Main attachment", + type: "many2one", + } +}); //-------------------------------------------------------------------------- // Insertion of records diff --git a/addons/mail/static/tests/web/chatter_tests.js b/addons/mail/static/tests/web/chatter_tests.js index 93b6048bfe6..b7c6021e431 100644 --- a/addons/mail/static/tests/web/chatter_tests.js +++ b/addons/mail/static/tests/web/chatter_tests.js @@ -6,7 +6,7 @@ import { DELAY_FOR_SPINNER } from "@mail/core/web/chatter"; import { patchUiSize, SIZES } from "@mail/../tests/helpers/patch_ui_size"; import { start } from "@mail/../tests/helpers/test_utils"; -import { makeDeferred, patchWithCleanup, triggerHotkey } from "@web/../tests/helpers/utils"; +import { getFixture, makeDeferred, patchWithCleanup, triggerHotkey } from "@web/../tests/helpers/utils"; import { click, contains, @@ -228,6 +228,50 @@ QUnit.test("chatter: drop attachments", async () => { await contains(".o-mail-AttachmentCard", { count: 3 }); }); +QUnit.test("chatter: drop attachment should refresh thread data with hasParentReloadOnAttachmentsChange prop", async () => { + patchUiSize({ size: SIZES.XXL }); + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({}); + const views = { + "res.partner,false,form": ` +
+ + + +
+
+ + +
+ `, + }; + const target = getFixture(); + target.classList.add("o_web_client"); + const { openFormView } = await start({ + serverData: { views }, + target, + async mockRPC(route) { + if (route === "/mail/attachment/upload") { + const attachmentId = pyEnv["ir.attachment"].create([ + { res_id: partnerId, res_model: "res.partner", mimetype: "application/pdf" } + ]); + pyEnv["res.partner"].write([partnerId], { message_main_attachment_id: attachmentId }); + return Promise.resolve(); + } + }, + }); + await openFormView("res.partner", partnerId); + const files = [ + await createFile({ + contentType: "application/pdf", + name: "text.pdf", + }), + ]; + await dragenterFiles(".o-mail-Chatter", files); + await dropFiles(".o-mail-Dropzone", files); + await contains(".o-mail-Attachment iframe", { count: 1 }); +}); + QUnit.test("should display subject when subject isn't infered from the record", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({});