summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriFP <113114423+andrifp@users.noreply.github.com>2025-09-13 10:59:33 +0700
committerAndriFP <113114423+andrifp@users.noreply.github.com>2025-09-13 10:59:33 +0700
commitfc83d226a0b49c1d0423f6e3ccadd353b1c45218 (patch)
treed9b8d59426ba8989aa1cd88130a478da71a03375
parent0c516cc828e3494074af0a63945c80c1954911ce (diff)
(andri) add attachment di email
-rw-r--r--indoteknik_custom/models/letter_receivable.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py
index 3823a57a..4f1395fe 100644
--- a/indoteknik_custom/models/letter_receivable.py
+++ b/indoteknik_custom/models/letter_receivable.py
@@ -7,6 +7,7 @@ import re
import logging
from datetime import timedelta
import babel
+import base64
_logger = logging.getLogger(__name__)
@@ -203,11 +204,25 @@ class SuratPiutang(models.Model):
.replace('${object.seven_days_after_sent_date}', self.seven_days_after_sent_date or '') \
.replace('${object.perihal}', perihal_text or '')
+ report = self.env.ref('indoteknik_custom.action_report_surat_piutang')
+ pdf_content, _ = report._render_qweb_pdf([self.id])
+ attachment_base64 = base64.b64encode(pdf_content)
+
+ attachment = self.env['ir.attachment'].create({
+ 'name': f"Surat Piutang {self.name}.pdf",
+ 'type': 'binary',
+ 'datas': attachment_base64,
+ 'res_model': 'surat.piutang',
+ 'res_id': self.id,
+ 'mimetype': 'application/pdf',
+ })
+
values = {
'subject': template.subject.replace('${object.name}', self.name or ''),
'email_to': self.tujuan_email,
'email_from': 'finance@indoteknik.co.id',
'body_html': body_html,
+ 'attachments': [(attachment.name, attachment.datas)],
'reply_to': 'finance@indoteknik.co.id',
}