summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-07-09 11:32:19 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-07-09 11:32:19 +0700
commitdb98db3e34ac47eeea0fc53f215cb483d6c5d5f9 (patch)
treec2c0d2d8f8eab283a8f12b332ebe8b2113c07fd7 /indoteknik_custom/models
parent1a3b0976b06543a9b107897a906dc50a8bf9c3d2 (diff)
(andri) scheduler reminder due inv
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/account_move.py54
1 files changed, 54 insertions, 0 deletions
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 = []