From eb78b67e938f03d5708188255d63dc439e6dcc25 Mon Sep 17 00:00:00 2001 From: Arturo Flores Date: Wed, 21 Apr 2021 02:41:08 +0000 Subject: [PATCH] [IMP] account_edi: improve how we handle attachments for the email When assembling the email we are leaving the assignment of the attachments to another method that we can inherit and then modify instead of doing it in the same method to attach them. The idea is that in any localization we need only to modify that method in order to add new attachments to the mail template. closes odoo/odoo#80490 X-original-commit: 6f2e7dc3e8c468bcdb0862468eb08b65ce40c983 Related: odoo/enterprise#22568 Signed-off-by: Laurent Smet --- addons/account_edi/models/mail_template.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/account_edi/models/mail_template.py b/addons/account_edi/models/mail_template.py index 7c48fce3a74..e809d323860 100644 --- a/addons/account_edi/models/mail_template.py +++ b/addons/account_edi/models/mail_template.py @@ -6,6 +6,17 @@ from odoo import api, models class MailTemplate(models.Model): _inherit = "mail.template" + def _get_edi_attachments(self, document): + """ + Will return the information about the attachment of the edi document for adding the attachment in the mail. + Can be overridden where e.g. a zip-file needs to be sent with the individual files instead of the entire zip + :param document: an edi document + :return: list with a tuple with the name and base64 content of the attachment + """ + if not document.attachment_id: + return [] + return [(document.attachment_id.name, document.attachment_id.datas)] + def generate_email(self, res_ids, fields): res = super().generate_email(res_ids, fields) @@ -26,10 +37,7 @@ class MailTemplate(models.Model): # wizard. if doc.edi_format_id._is_embedding_to_invoice_pdf_needed(): continue - - attachment = doc.attachment_id - if attachment: - record_data.setdefault('attachments', []) - record_data['attachments'].append((attachment.name, attachment.datas)) + record_data.setdefault('attachments', []) + record_data['attachments'] += self._get_edi_attachments(doc) return res