From fc83d226a0b49c1d0423f6e3ccadd353b1c45218 Mon Sep 17 00:00:00 2001 From: AndriFP <113114423+andrifp@users.noreply.github.com> Date: Sat, 13 Sep 2025 10:59:33 +0700 Subject: (andri) add attachment di email --- indoteknik_custom/models/letter_receivable.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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', } -- cgit v1.2.3