From 742effec8d48e83713c143853b2f42a957ddc07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 2 Apr 2019 13:55:00 +0000 Subject: [PATCH] [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 --- addons/mail/models/mail_template.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 3b8732d86ac..7ed1b6a53ea 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -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)