From d3707cf95410bfa79bd43cfabd00245b4d59db25 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 23 Aug 2023 14:11:00 +0000 Subject: [PATCH] [IMP] account: allow to remove placeholders attachments in send & print wizard In 16.1 and before, when you used the Send & Print, you could manually remove the attachments when using the Send by Email. Even though the use case is weird (sending an invoice by email without attaching the document), we have feedback of user actively using that option before. Also, prevent the deletion of the PDF report from the wizard: - Create and invoice and send it by mail - Open again the send & print, remove the PDF and send by mail => The PDF is deleted from the invoice closes odoo/odoo#135101 Task: 3476700 Opw: 3378840 X-original-commit: 00dc68955c8e4c35fab29617eed7f03e45fc6643 Signed-off-by: Florian Gilbert (flg) Signed-off-by: Laurent Smet (las) --- .../mail_attachments/mail_attachments.js | 16 ++++-- .../mail_attachments/mail_attachments.xml | 51 ++++++++++++------- addons/account/wizard/account_move_send.py | 8 ++- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/addons/account/static/src/components/mail_attachments/mail_attachments.js b/addons/account/static/src/components/mail_attachments/mail_attachments.js index 2e845c1132a..e254da4d354 100644 --- a/addons/account/static/src/components/mail_attachments/mail_attachments.js +++ b/addons/account/static/src/components/mail_attachments/mail_attachments.js @@ -55,12 +55,20 @@ export class MailAttachments extends Component { } onFileRemove(deleteId) { - for(let item of this.getValue()){ - if(item.id == deleteId && !item.placeholder){ - this.attachmentIdsToUnlink.add(item.id); + const newValue = []; + for (let item of this.getValue()) { + if (item.id === deleteId) { + if (item.placeholder || item.protect_from_deletion) { + const copyItem = Object.assign({ skip: true }, item); + newValue.push(copyItem); + } else { + this.attachmentIdsToUnlink.add(item.id); + } + } else { + newValue.push(item); } } - this.props.record.update({ [this.props.name]: this.getValue().filter((item) => !this.attachmentIdsToUnlink.has(item.id)) }); + this.props.record.update({ [this.props.name]: newValue }); } async onWillUnmount(){ diff --git a/addons/account/static/src/components/mail_attachments/mail_attachments.xml b/addons/account/static/src/components/mail_attachments/mail_attachments.xml index df4b53ca4f0..698e5fa5946 100644 --- a/addons/account/static/src/components/mail_attachments/mail_attachments.xml +++ b/addons/account/static/src/components/mail_attachments/mail_attachments.xml @@ -3,26 +3,39 @@ - - -