[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) <flg@odoo.com>
Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
Laurent Smet
2023-09-12 08:31:42 +00:00
parent 57da33a9ff
commit d3707cf954
3 changed files with 52 additions and 23 deletions
@@ -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(){
@@ -3,26 +3,39 @@
<t t-name="account.mail_attachment_file"
t-inherit="web.Many2ManyBinaryField.attachment_preview"
t-inherit-mode="primary"
>
<xpath expr="//div[hasclass('o_attachment_wrap')]" position="after">
<!-- lite display for placeholder files -->
<div class="o_attachment_wrap" t-if="file.placeholder">
<div class="o_image_box float-start">
<span class="o_image o_hover" t-att-data-mimetype="file.mimetype" t-att-data-ext="ext" role="img" style="height:15px;width:30px;"/>
</div>
<div class="caption">
<t t-esc='file.name'/>
</div>
t-inherit-mode="primary">
<!-- Remove the download on hover for placeholder. -->
<xpath expr="//div[hasclass('o_image_box', 'float-start')]" position="replace">
<div class="o_image_box float-start"
t-att="{
'data-tooltip': !file.placeholder ? `Download ${file.name}` : undefined,
}"
>
<a t-att="{
'href': !file.placeholder ? url : undefined,
'aria-label': !file.placeholder ? 'Download' : undefined,
'download': !file.placeholder ? '' : undefined,
}"
>
<span class="o_image o_hover"
style="height:15px;width:30px;"
t-att-data-mimetype="file.mimetype"
t-att-data-ext="ext"
role="img"/>
</a>
</div>
</xpath>
<xpath expr="//div[hasclass('o_attachment_wrap')]" position="attributes">
<attribute name="t-if">!file.placeholder</attribute>
</xpath>
<xpath expr="//div[hasclass('caption','small')]" position="replace"/>
<xpath expr="//span[hasclass('o_image','o_hover')]" position="attributes">
<attribute name="style">height:15px;width:30px;</attribute>
<xpath expr="//div[hasclass('caption')]/a" position="replace">
<a class="ml4"
t-att="{
'data-tooltip': !file.placeholder ? `Download ${file.name}` : undefined,
'href': !file.placeholder ? url : undefined,
'download': !file.placeholder ? '' : undefined,
}"
t-esc='file.name'/>
</xpath>
<!-- Remove the mimetype on the second line. -->
<xpath expr="//div[hasclass('caption', 'small')]" position="replace"/>
</t>
<t t-name="account.mail_attachments">
@@ -31,7 +44,9 @@
<div t-attf-class="oe_fileupload" aria-atomic="true">
<div class="o_attachments">
<t t-foreach="data" t-as="file" t-key="file.id">
<t t-call="account.mail_attachment_file"/>
<t t-if="!file.skip">
<t t-call="account.mail_attachment_file"/>
</t>
</t>
</div>
<div t-if="!props.readonly" class="oe_add">
+7 -1
View File
@@ -139,6 +139,7 @@ class AccountMoveSend(models.Model):
'name': attachment.name,
'mimetype': attachment.mimetype,
'placeholder': False,
'protect_from_deletion': True,
}
for attachment in self._get_invoice_extra_attachments(move)
]
@@ -457,7 +458,12 @@ class AccountMoveSend(models.Model):
# We must ensure the newly created PDF are added. At this point, the PDF has been generated but not added
# to 'mail_attachments_widget'.
seen_attachment_ids = set()
for attachment_data in self._get_invoice_extra_attachments_data(self.move_ids) + (self.mail_attachments_widget or []):
mail_attachments_widget = self.mail_attachments_widget or []
to_exclude = set(x['name'] for x in mail_attachments_widget if x.get('skip'))
for attachment_data in self._get_invoice_extra_attachments_data(self.move_ids) + mail_attachments_widget:
if attachment_data['name'] in to_exclude:
continue
try:
attachment_id = int(attachment_data['id'])
except ValueError: