diff options
| -rw-r--r-- | indoteknik_custom/models/letter_receivable.py | 15 |
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', } |
