From c72db0d0fa214e6691fa9a293020e7091a9c82c2 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 9 Jul 2025 13:42:33 +0700 Subject: (andri) fix invoices --- indoteknik_custom/models/account_move.py | 36 ++++++++++-------- .../views/mail_template_invoice_reminder.xml | 43 ++++++++++++---------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 8ef3d273..e63f4cb2 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -76,12 +76,9 @@ class AccountMove(models.Model): 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', 'DAYA ANUGRAH MULYA')], limit=1) + partner = self.env['res.partner'].search([('name', 'ilike', 'TIRTA FRESINDO JAYA')], limit=1) if not partner: _logger.info("Partner tidak ditemukan.") return @@ -92,6 +89,7 @@ class AccountMove(models.Model): ('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=0)), ('invoice_date_due', '<=', today + timedelta(days=3)), ('invoice_date_due', '<=', today + timedelta(days=7)), ('partner_id', '=', partner.id), @@ -115,17 +113,25 @@ class AccountMove(models.Model): # 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)}") + try: + template.with_context(invoices=invoices).send_mail(partner.id, force_send=True, email_values={ + 'email_to': 'andrifebriyadiputra@gmail.com', # test override + }) + _logger.info(f"Reminder terkirim ke {partner.name} → {len(invoices)} invoice") + except Exception as e: + _logger.error(f"Gagal kirim email ke {partner.name}: {str(e)}") + + # 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 index b19171b2..176a68ba 100644 --- a/indoteknik_custom/views/mail_template_invoice_reminder.xml +++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml @@ -3,22 +3,23 @@ Invoice Reminder: Due Date Notification - - [Reminder] Invoice ${object.name} is Due Soon + + [Reminder] Invoice Due Summary for ${object.name} finance@indoteknik.co.id - finance@indoteknik.co.id andrifebriyadiputra@gmail.com +
-

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

+

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

-

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

+

Berikut adalah daftar invoice Anda yang mendekati atau telah jatuh tempo:

+ - + @@ -26,30 +27,34 @@ - - - - - - - - + + + + + + + + + + + + +
No Invoice NumberTanggal InvoiceTanggal Jatuh Tempo Sisa Hari Total
${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.

+

Mohon segera melakukan proses pembayaran. Terima kasih.

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 + Telp: 021-2933 8828 / 29
+ Email: finance@indoteknik.co.id

+
-- cgit v1.2.3