summaryrefslogtreecommitdiff
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
parent1a3b0976b06543a9b107897a906dc50a8bf9c3d2 (diff)
(andri) scheduler reminder due inv
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rw-r--r--indoteknik_custom/models/account_move.py54
-rw-r--r--indoteknik_custom/views/mail_template_invoice_reminder.xml55
3 files changed, 110 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data noupdate="1">
+ <record id="mail_template_invoice_due_reminder" model="mail.template">
+ <field name="name">Invoice Reminder: Due Date Notification</field>
+ <field name="model_id" ref="account.model_account_move"/>
+ <field name="subject">[Reminder] Invoice ${object.name} is Due Soon</field>
+ <field name="email_from">finance@indoteknik.co.id</field>
+ <field name="reply_to">finance@indoteknik.co.id</field>
+ <field name="email_to">andrifebriyadiputra@gmail.com</field>
+ <field name="body_html" type="html">
+ <div style="font-family:Arial, sans-serif; font-size:14px;">
+ <p>Dengan Hormat Bpk/Ibu ${object.partner_id.name},</p>
+
+ <p>Berikut adalah detail invoice Anda yang sudah mendekati atau telah jatuh tempo:</p>
+
+ <table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse; width: 100%;">
+ <thead>
+ <tr style="background-color: #f2f2f2;">
+ <th>Invoice Number</th>
+ <th>Tanggal Invoice</th>
+ <th>Jatuh Tempo</th>
+ <th>Sisa Hari</th>
+ <th>Total</th>
+ <th>Referensi</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>${object.name}</td>
+ <td>${format_date(object.invoice_date)}</td>
+ <td>${format_date(object.invoice_date_due)}</td>
+ <td>${object.invoice_day_to_due}</td>
+ <td>${format_amount(object.amount_total, object.currency_id)}</td>
+ <td>${object.ref or '-'}</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <p>Mohon segera melakukan proses pembayaran sebelum jatuh tempo.</p>
+
+ <p>Terima kasih atas perhatian dan kerjasamanya.</p>
+
+ <p>
+ Hormat Kami,<br/>
+ <strong>PT. INDOTEKNIK DOTCOM GEMILANG</strong><br/>
+ Jl. Bandengan Utara 85A No. 8-9, Penjaringan, Jakarta Utara<br/>
+ Telp: 021-2933 8828 / 29 | Email: finance@indoteknik.co.id
+ </p>
+ </div>
+ </field>
+ <field name="auto_delete" eval="True"/>
+ </record>
+ </data>
+</odoo>