From b74506f96049cbfd5ea475a12479e9d3a5337575 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 26 Jun 2024 16:30:57 +0700 Subject: send email faktur pajak --- indoteknik_custom/models/account_move.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'indoteknik_custom/models/account_move.py') 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 @@ -63,6 +63,38 @@ class AccountMove(models.Model): flag_delivery_amt = fields.Boolean(string="Flag Delivery Amount", compute='compute_flag_delivery_amt') 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' -- cgit v1.2.3 From e33f2d321ee4db6a6e6a86e35243100b9f107f22 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 27 Jun 2024 15:29:16 +0700 Subject: logbook bill & send email efaktur document --- indoteknik_custom/models/account_move.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index d81726e9..2996623c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -66,7 +66,6 @@ class AccountMove(models.Model): @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 @@ -79,21 +78,18 @@ class AccountMove(models.Model): }) return attachment - @api.model + @api.constrains('efaktur_document') 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)]) + 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) + template.send_mail(record.id, email_values=email_values, force_send=True) @api.model def create(self, vals): -- cgit v1.2.3 From 53e2b4ba69c7d0ea7a401ea6cc810dbcbf0fe46a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 28 Jun 2024 08:49:18 +0700 Subject: deactivate code send email efaktur document --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 2996623c..fbadd2aa 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -78,7 +78,7 @@ class AccountMove(models.Model): }) return attachment - @api.constrains('efaktur_document') + # @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)]) -- cgit v1.2.3