summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/account_move.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/account_move.py')
-rw-r--r--indoteknik_custom/models/account_move.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 0ba25ad8..fbadd2aa 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -64,6 +64,34 @@ class AccountMove(models.Model):
nomor_kwitansi = fields.Char(string="Nomor Kwitansi")
@api.model
+ def generate_attachment(self, record):
+ # Fetch the binary field
+ 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.constrains('efaktur_document')
+ def send_scheduled_email(self):
+ # Get the records for which emails need to be sent
+ records = self.search([('id', 'in', self.ids)])
+ template = self.env.ref('indoteknik_custom.mail_template_efaktur_document')
+
+ 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, force_send=True)
+
+ @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)