[FIX] mail_template: correctly compute / update attachment_ids in send mail
Attachments when generating an email based on a template are done in two steps, see notably [1]. However mail generation replaces attachments using a 6 command. This means existing attachments given through email_values are not correctly managed and this leads to invalid command given to the m2m field. This commit fixes that by correctly generating a list of commands, using 4 (add) for new attachments coming notably from reports linked to the template. Related task ID 1965040 PR #32459 [1] https://github.com/odoo/odoo/commit/f789005c9a6c26322565a1af7cc4e57a60eab9f0
This commit is contained in:
@@ -512,6 +512,7 @@ class MailTemplate(models.Model):
|
||||
# create a mail_mail based on values, without attachments
|
||||
values = self.generate_email(res_id)
|
||||
values['recipient_ids'] = [(4, pid) for pid in values.get('partner_ids', list())]
|
||||
values['attachment_ids'] = [(4, aid) for aid in values.get('attachment_ids', list())]
|
||||
values.update(email_values or {})
|
||||
attachment_ids = values.pop('attachment_ids', [])
|
||||
attachments = values.pop('attachments', [])
|
||||
@@ -545,10 +546,9 @@ class MailTemplate(models.Model):
|
||||
'res_model': 'mail.message',
|
||||
'res_id': mail.mail_message_id.id,
|
||||
}
|
||||
attachment_ids.append(Attachment.create(attachment_data).id)
|
||||
attachment_ids.append((4, Attachment.create(attachment_data).id))
|
||||
if attachment_ids:
|
||||
values['attachment_ids'] = [(6, 0, attachment_ids)]
|
||||
mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
|
||||
mail.write({'attachment_ids': attachment_ids})
|
||||
|
||||
if force_send:
|
||||
mail.send(raise_exception=raise_exception)
|
||||
|
||||
Reference in New Issue
Block a user