Files
odoo_source/addons/account_edi/models/mail_template.py
T
Josse Colpaert dc40a5a01c [FIX] account_edi: also send electronic document for the payments
When we want to send the invoice to the client, a hack was made in account_edi
to make sure that we put the XML of the electronic invoice formats as well, in
the case of web services such that the client has the XML we sent to the government.

For MX however, we also send the payment to the government.  However when we wanted
to send the confirmation about the different changes, we still needed to add the XML
manually before this fix.  Now it should be added manually even when manually composing
the mail to the customer with the payment receipt confirmation.  (but we hope it dies)

closes odoo/odoo#67315

X-original-commit: 327852a6399a19191bd78c820971cc4108dc7821
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: Josse Colpaert <jco@openerp.com>
2021-03-05 09:20:58 +00:00

36 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from odoo import api, models
class MailTemplate(models.Model):
_inherit = "mail.template"
def generate_email(self, res_ids, fields):
res = super().generate_email(res_ids, fields)
multi_mode = True
if isinstance(res_ids, int):
res_ids = [res_ids]
multi_mode = False
if self.model not in ['account.move', 'account.payment']:
return res
records = self.env[self.model].browse(res_ids)
for record in records:
record_data = (res[record.id] if multi_mode else res)
for doc in record.edi_document_ids:
# The EDI format will be embedded directly inside the PDF and then, don't need to be added to the
# 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))
return res