diff --git a/addons/account_edi/models/mail_template.py b/addons/account_edi/models/mail_template.py index 3e3c07dbe59..37fbf401e83 100644 --- a/addons/account_edi/models/mail_template.py +++ b/addons/account_edi/models/mail_template.py @@ -8,14 +8,24 @@ class MailTemplate(models.Model): def _get_edi_attachments(self, document): """ - Will return the information about the attachment of the edi document for adding the attachment in the mail. + Will either return the information about the attachment of the edi document for adding the attachment in the + mail, or the attachment id to be linked to the 'send & print' wizard. Can be overridden where e.g. a zip-file needs to be sent with the individual files instead of the entire zip + IMPORTANT: + * If the attachment's id is returned, no new attachment will be created, the existing one on the move is linked + to the wizard (see _onchange_template_id in mail.compose.message). + * If the attachment's content is returned, a new one is created and linked to the wizard. Thus, when sending + the mail (clicking on 'send & print' in the wizard), a new attachment is added to the move (see + _action_send_mail in mail.compose.message). :param document: an edi document - :return: list with a tuple with the name and base64 content of the attachment + :return: dict: + {'attachments': tuple with the name and base64 content of the attachment} + OR + {'attachment_ids': list containing the id of the attachment} """ if not document.attachment_id: - return [] - return [(document.attachment_id.name, document.attachment_id.datas)] + return {} + return {'attachment_ids': [document.attachment_id.id]} def generate_email(self, res_ids, fields): res = super().generate_email(res_ids, fields) @@ -33,6 +43,8 @@ class MailTemplate(models.Model): record_data = (res[record.id] if multi_mode else res) for doc in record.edi_document_ids: record_data.setdefault('attachments', []) - record_data['attachments'] += self._get_edi_attachments(doc) + attachments = self._get_edi_attachments(doc) + record_data['attachment_ids'] += attachments.get('attachment_ids', []) + record_data['attachments'] += attachments.get('attachments', []) return res diff --git a/addons/account_edi_ubl_cii/models/__init__.py b/addons/account_edi_ubl_cii/models/__init__.py index fab68bf1e70..67afac14748 100644 --- a/addons/account_edi_ubl_cii/models/__init__.py +++ b/addons/account_edi_ubl_cii/models/__init__.py @@ -10,3 +10,4 @@ from . import account_edi_xml_ubl_xrechnung from . import account_edi_xml_ubl_nlcius from . import account_edi_xml_ubl_efff from . import ir_actions_report +from . import mail_template diff --git a/addons/account_edi_ubl_cii/models/mail_template.py b/addons/account_edi_ubl_cii/models/mail_template.py new file mode 100644 index 00000000000..43dd4f3d08e --- /dev/null +++ b/addons/account_edi_ubl_cii/models/mail_template.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from odoo import models + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + def _get_edi_attachments(self, document): + # EXTENDS account_edi + # Avoid having factur-x.xml in the 'send & print' wizard + if document.edi_format_id.code == 'facturx_1_0_05': + return {} + return super()._get_edi_attachments(document) diff --git a/addons/l10n_it_edi/models/mail_template.py b/addons/l10n_it_edi/models/mail_template.py index 1bd7999a07d..a41d9524233 100644 --- a/addons/l10n_it_edi/models/mail_template.py +++ b/addons/l10n_it_edi/models/mail_template.py @@ -14,5 +14,5 @@ class MailTemplate(models.Model): :return: list with a tuple with the name and base64 content of the attachment """ if document.edi_format_id.code == 'fattura_pa': - return [] + return {} return super()._get_edi_attachments(document)