diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-07-09 13:42:33 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-07-09 13:42:33 +0700 |
| commit | c72db0d0fa214e6691fa9a293020e7091a9c82c2 (patch) | |
| tree | 4ee863d201b99cd7878b24fed923597d64534511 /indoteknik_custom/models | |
| parent | 5e905a9af7f6bb928c44cad2d47f8c6e69662bd2 (diff) | |
(andri) fix invoices
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 36 |
1 files changed, 21 insertions, 15 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 = [] |
