summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-07-09 04:35:16 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-07-09 04:35:16 +0000
commitad638c9e0c24df33f86bd66f995a56cbd63b1283 (patch)
tree81bb8d5ac322df65a88f1e8a525a7970a186e7de /indoteknik_custom/models
parent0604dbc3a2789c139ea66dd561726f796ad92cd6 (diff)
parentdb98db3e34ac47eeea0fc53f215cb483d6c5d5f9 (diff)
Merged in reminder-tempo (pull request #349)
(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 = []