From db98db3e34ac47eeea0fc53f215cb483d6c5d5f9 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 9 Jul 2025 11:32:19 +0700 Subject: (andri) scheduler reminder due inv --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/account_move.py | 54 +++++++++++++++++++++ .../views/mail_template_invoice_reminder.xml | 55 ++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 indoteknik_custom/views/mail_template_invoice_reminder.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 17cec7b6..21afc26f 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -97,6 +97,7 @@ 'views/mail_template_po.xml', 'views/mail_template_efaktur.xml', 'views/mail_template_invoice_po.xml', + 'views/mail_template_invoice_reminder.xml', 'views/price_group.xml', 'views/mrp_production.xml', 'views/apache_solr.xml', diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index b6627867..df79b9f6 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -8,12 +8,14 @@ import PyPDF2 import os import re from terbilang import Terbilang +from collections import defaultdict _logger = logging.getLogger(__name__) class AccountMove(models.Model): _inherit = 'account.move' + _description = 'Account Move' invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due") bill_day_to_due = fields.Date(string="Day to Due", compute="_compute_bill_day_to_due") date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak") @@ -72,6 +74,58 @@ class AccountMove(models.Model): bill_id = fields.Many2one('account.move', string='Vendor Bill', domain=[('move_type', '=', 'in_invoice')], help='Bill asal dari proses reklas ini') down_payment = fields.Boolean('Down Payments?') + def send_due_invoice_reminder(self): + today = fields.Date.today() + reminder_days = [-7, -3, 0, 3, 7] + target_dates = [today + timedelta(days=delta) for delta in reminder_days] + target_dates_str = [d.isoformat() for d in target_dates] + + # Ganti nama partner untuk test jika perlu + partner = self.env['res.partner'].search([('name', 'ilike', 'PRIMA SEJAHTERA MARITIM')], limit=1) + if not partner: + _logger.info("Partner tidak ditemukan.") + return + + invoices = self.env['account.move'].search([ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('payment_state', 'not in', ['paid','in_payment', 'reversed']), + ('invoice_date_due', '>=', today - timedelta(days=7)), + ('invoice_date_due', '>=', today - timedelta(days=3)), + ('invoice_date_due', '<=', today + timedelta(days=3)), + ('invoice_date_due', '<=', today + timedelta(days=7)), + ('partner_id', '=', partner.id), + ]) + + _logger.info(f"Invoices tahap 1: {invoices}") + + # Filter berdasarkan term mengandung "tempo" + invoices = invoices.filtered( + lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() + ) + _logger.info(f"Invoices tahap 2: {invoices}") + + if not invoices: + _logger.info(f"Tidak ada invoice yang due untuk partner: {partner.name}") + return + + # Pastikan field compute jalan + invoices._compute_invoice_day_to_due() + + # Ambil template + template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') + + for inv in invoices: + try: + # Untuk test: override ke email pribadi Anda + email_values = { + 'email_to': 'andrifebriyadiputra@gmail.com', + 'email_from': 'finance@indoteknik.co.id', + } + template.send_mail(inv.id, force_send=True, email_values=email_values) + _logger.info(f"Reminder terkirim: {inv.name} → {email_values['email_to']}") + except Exception as e: + _logger.error(f"Gagal kirim email untuk {inv.name}: {str(e)}") # def name_get(self): # result = [] diff --git a/indoteknik_custom/views/mail_template_invoice_reminder.xml b/indoteknik_custom/views/mail_template_invoice_reminder.xml new file mode 100644 index 00000000..b19171b2 --- /dev/null +++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml @@ -0,0 +1,55 @@ + + + + + Invoice Reminder: Due Date Notification + + [Reminder] Invoice ${object.name} is Due Soon + finance@indoteknik.co.id + finance@indoteknik.co.id + andrifebriyadiputra@gmail.com + +
+

Dengan Hormat Bpk/Ibu ${object.partner_id.name},

+ +

Berikut adalah detail invoice Anda yang sudah mendekati atau telah jatuh tempo:

+ + + + + + + + + + + + + + + + + + + + + + +
Invoice NumberTanggal InvoiceJatuh TempoSisa HariTotalReferensi
${object.name}${format_date(object.invoice_date)}${format_date(object.invoice_date_due)}${object.invoice_day_to_due}${format_amount(object.amount_total, object.currency_id)}${object.ref or '-'}
+ +

Mohon segera melakukan proses pembayaran sebelum jatuh tempo.

+ +

Terima kasih atas perhatian dan kerjasamanya.

+ +

+ Hormat Kami,
+ PT. INDOTEKNIK DOTCOM GEMILANG
+ Jl. Bandengan Utara 85A No. 8-9, Penjaringan, Jakarta Utara
+ Telp: 021-2933 8828 / 29 | Email: finance@indoteknik.co.id +

+
+
+ +
+
+
-- cgit v1.2.3