diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-06-26 16:30:57 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-06-26 16:30:57 +0700 |
| commit | b74506f96049cbfd5ea475a12479e9d3a5337575 (patch) | |
| tree | 1f2996266ac7118c88789ee24d4c698ab1dfb2a2 | |
| parent | c790750afd36ed86772477bce9307b16689910c4 (diff) | |
send email faktur pajak
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 0ba25ad8..d81726e9 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -64,6 +64,38 @@ class AccountMove(models.Model): nomor_kwitansi = fields.Char(string="Nomor Kwitansi") @api.model + def generate_attachment(self, record): + # Fetch the binary field + # TODO nathan tolong rapihin + file_content = record.efaktur_document + file_name = "efaktur_document_{}.pdf".format(record.id) # Adjust the file extension if necessary + + attachment = self.env['ir.attachment'].create({ + 'name': file_name, + 'type': 'binary', + 'datas': file_content, + 'res_model': record._name, + 'res_id': record.id, + }) + return attachment + + @api.model + def send_scheduled_email(self): + # Get the records for which emails need to be sent + # records = self.search([]) # Adjust the domain as necessary + # TODO nathan tolong rapihin + records = self.env['account.move'].search([('id', '=', 194697)]) + # template = self.env.ref('my_module.email_template_example') + template = self.env['mail.template'].search([('id', '=', 8)]) + + for record in records: + attachment = self.generate_attachment(record) + email_values = { + 'attachment_ids': [(4, attachment.id)] + } + template.send_mail(record.id, email_values=email_values) + + @api.model def create(self, vals): vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' result = super(AccountMove, self).create(vals) |
