From c9be0631a9340fb4b1d8bde9304bb6d678f82bcb Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Tue, 30 Jul 2019 12:49:14 +0200 Subject: [PATCH] [FIX] account_credit_control: Unknown field attachments WARNING prod odoo.models: mail.mail.create() includes unknown fields: attachments --- .../wizard/credit_control_communication.py | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/account_credit_control/wizard/credit_control_communication.py b/account_credit_control/wizard/credit_control_communication.py index 6abbf53d1..17df8da51 100644 --- a/account_credit_control/wizard/credit_control_communication.py +++ b/account_credit_control/wizard/credit_control_communication.py @@ -166,6 +166,16 @@ class CreditCommunication(models.TransientModel): # of storing res_id email_values.pop('model', None) email_values.pop('res_id', None) + + # Remove when mail.template returns correct format attachments + attachment_list = email_values.pop('attachments', None) + email_values['attachment_ids'] = [(0, 0, { + 'name': att[0], + 'datas': att[1], + 'datas_fname': att[0], + 'type': 'binary', + }) for att in attachment_list] + email = emails.create(email_values) state = 'sent' @@ -179,20 +189,6 @@ class CreditCommunication(models.TransientModel): comm.credit_control_line_ids.write({'mail_message_id': email.id, 'state': state}) - attachments = self.env['ir.attachment'] - for att in email_values.get('attachments', []): - attach_fname = att[0] - attach_datas = att[1] - data_attach = { - 'name': attach_fname, - 'datas': attach_datas, - 'datas_fname': attach_fname, - 'res_model': 'mail.mail', - 'res_id': email.id, - 'type': 'binary', - } - attachments |= attachments.create(data_attach) - email.write({'attachment_ids': [(6, 0, attachments.ids)]}) emails += email return emails