summaryrefslogtreecommitdiff
path: root/addons/account_edi/models/mail_template.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_edi/models/mail_template.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_edi/models/mail_template.py')
-rw-r--r--addons/account_edi/models/mail_template.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/addons/account_edi/models/mail_template.py b/addons/account_edi/models/mail_template.py
new file mode 100644
index 00000000..7c48fce3
--- /dev/null
+++ b/addons/account_edi/models/mail_template.py
@@ -0,0 +1,35 @@
+# -*- 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