summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-08-28 09:38:36 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-08-28 09:38:36 +0000
commit0112ac064a7484685119cf9371ffbea32de6fd59 (patch)
tree69ba30254539ecb1e881a887e04bf0537ba461c5
parent26623e1b2e8ba83367814ac704fbb19a4370f56c (diff)
parent6f6c6c86d91c811984d6ce6c478f4024cd4fb3ed (diff)
Merged in reminder-tempo-v2 (pull request #394)
Reminder tempo v2
-rw-r--r--indoteknik_custom/models/account_move.py72
-rw-r--r--indoteknik_custom/views/mail_template_invoice_reminder.xml55
2 files changed, 98 insertions, 29 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 905855c6..c44cad78 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -179,8 +179,9 @@ class AccountMove(models.Model):
('state', '=', 'posted'),
('payment_state', 'not in', ['paid', 'in_payment', 'reversed']),
('invoice_date_due', 'in', target_dates),
- ('date_terima_tukar_faktur', '!=', False)
- ])
+ ('date_terima_tukar_faktur', '!=', False),
+ ('partner_id', 'in' , [94603])
+ ], limit=5)
_logger.info(f"Invoices: {invoices}")
invoices = invoices.filtered(
@@ -247,8 +248,10 @@ class AccountMove(models.Model):
_logger.info(f"Email tujuan: {email_to}")
invoice_table_rows = ""
+ grand_total = 0
for inv in invs:
days_to_due = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0
+ grand_total += inv.amount_total
invoice_table_rows += f"""
<tr>
<td>{inv.partner_id.name}</td>
@@ -261,6 +264,66 @@ class AccountMove(models.Model):
<td>{days_to_due}</td>
</tr>
"""
+ invoice_table_footer = f"""
+ <tfoot>
+ <tr style="font-weight:bold; background-color:#f9f9f9;">
+ <td colspan="5" align="right">Grand Total</td>
+ <td>{formatLang(self.env, grand_total, currency_obj=invs[0].currency_id)}</td>
+ <td colspan="2"></td>
+ </tr>
+ </tfoot>
+ """
+
+ blocking_limit = partner.blocking_stage or 0.0
+
+ # semua invoice tempo yang masih open
+ outstanding_invoices = self.env['account.move'].search([
+ ('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
+ ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']),
+ ('partner_id', '=', partner.id),
+ ('invoice_payment_term_id.name', 'ilike', 'tempo')
+ ])
+
+ outstanding_amount = sum(outstanding_invoices.mapped('amount_total'))
+
+ # invoice tempo yang sudah jatuh tempo
+ overdue_invoices = outstanding_invoices.filtered(
+ lambda inv: inv.invoice_date_due and inv.invoice_date_due < fields.Date.today()
+ )
+
+ overdue_amount = sum(overdue_invoices.mapped('amount_total'))
+
+ currency = invs[0].currency_id if invs else partner.company_id.currency_id
+ tempo_link = 'https://indoteknik.com/my/tempo'
+ # tempo_link = 'http://localhost:2100/my/tempo'
+
+ limit_info_html = f"""
+ <p><b>Informasi Tambahan:</b></p>
+ <ul style="font-size:12px; color:#333; line-height:1.4; margin:0; padding-left:0; list-style-position:inside;">
+ <li>Kredit Limit Anda: {formatLang(self.env, blocking_limit, currency_obj=currency)}</li>
+ <li>Status Detail Tempo: {partner.property_payment_term_id.name or 'Review'}</li>
+ <li style="color:{'red' if (blocking_limit - outstanding_amount) < 0 else 'green'};">
+ Sisa Kredit Limit: {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)}
+ </li>
+ <li style="color:red;">
+ Kredit Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)}
+ <span style="font-size:12px; color:#666;">({len(outstanding_invoices)} Transaksi)</span>
+ </li>
+ <li style="color:red;">
+ Jatuh Tempo: {formatLang(self.env, overdue_amount, currency_obj=currency)}
+ <span style="font-size:12px; color:#666;">({len(overdue_invoices)} Invoice)</span>
+ </li>
+ </ul>
+ <p style="margin-top:10px;">
+ <a href="{tempo_link or '#'}"
+ style="display:inline-block; padding:8px 16px;
+ background-color:#007bff; color:#fff; text-decoration:none;
+ border-radius:4px; font-size:12px;">
+ Cek Selengkapnya
+ </a>
+ </p>
+ """
days_to_due_message = ""
closing_message = ""
@@ -302,13 +365,14 @@ class AccountMove(models.Model):
body_html = re.sub(
r"<tbody[^>]*>.*?</tbody>",
- f"<tbody>{invoice_table_rows}</tbody>",
+ f"<tbody>{invoice_table_rows}</tbody>{invoice_table_footer}",
template.body_html,
flags=re.DOTALL
).replace('${object.name}', partner.name) \
.replace('${object.partner_id.name}', partner.name) \
.replace('${days_to_due_message}', days_to_due_message) \
- .replace('${closing_message}', closing_message)
+ .replace('${closing_message}', closing_message) \
+ .replace('${limit_info_html}', limit_info_html)
cc_list = [
'finance@indoteknik.co.id',
diff --git a/indoteknik_custom/views/mail_template_invoice_reminder.xml b/indoteknik_custom/views/mail_template_invoice_reminder.xml
index 8450be28..13c02a08 100644
--- a/indoteknik_custom/views/mail_template_invoice_reminder.xml
+++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml
@@ -8,45 +8,50 @@
<field name="email_from">finance@indoteknik.co.id</field>
<field name="email_to"></field>
<field name="body_html" type="html">
- <div>
+ <div style="font-family:Arial, sans-serif; font-size:13px; color:#333;">
<p><b>Dear ${object.name},</b></p>
<p>${days_to_due_message}</p>
- <table border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size: 12px">
+ <table cellpadding="6" cellspacing="0" width="100%"
+ style="border-collapse:collapse; font-size:12px; border:1px solid #ddd;">
<thead>
- <tr style="background-color: #f2f2f2;" align="left">
- <th>Customer</th>
- <th>No. PO</th>
- <th>Invoice Number</th>
- <th>Invoice Date</th>
- <th>Due Date</th>
- <th>Amount</th>
- <th>Term</th>
- <th>Days To Due</th>
+ <tr style="background-color:#f2f2f2; text-align:left;">
+ <th style="border:1px solid #ddd;">Customer</th>
+ <th style="border:1px solid #ddd;">No. PO</th>
+ <th style="border:1px solid #ddd;">Invoice Number</th>
+ <th style="border:1px solid #ddd;">Invoice Date</th>
+ <th style="border:1px solid #ddd;">Due Date</th>
+ <th style="border:1px solid #ddd;">Amount</th>
+ <th style="border:1px solid #ddd;">Term</th>
+ <th style="border:1px solid #ddd;">Days To Due</th>
</tr>
</thead>
<tbody>
+ <!-- baris invoice akan diinject dari Python -->
</tbody>
</table>
<p>${closing_message}</p>
+ ${limit_info_html}
<br/>
<p>Terima Kasih.</p>
- <br/>
- <br/>
- <p><b>Best Regards,
- <br/>
- <br/>
- Widya R.<br/>
- Dept. Finance<br/>
- PT. INDOTEKNIK DOTCOM GEMILANG<br/>
- <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2135765" alt="Indoteknik" style="max-width: 18%; height: auto;"></img><br/>
- <a href="https://wa.me/6285716970374" target="_blank">+62-857-1697-0374</a> |
- <a href="mailto:finance@indoteknik.co.id">finance@indoteknik.co.id</a>
- </b></p>
- <p><i>Email ini dikirim secara otomatis. Abaikan jika pembayaran telah dilakukan.</i></p>
-
+ <br/><br/>
+ <p>
+ <b>
+ Best Regards,<br/><br/>
+ Widya R.<br/>
+ Dept. Finance<br/>
+ PT. INDOTEKNIK DOTCOM GEMILANG<br/>
+ <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2135765"
+ alt="Indoteknik" style="max-width:18%; height:auto;"/><br/>
+ <a href="https://wa.me/6285716970374" target="_blank">+62-857-1697-0374</a> |
+ <a href="mailto:finance@indoteknik.co.id">finance@indoteknik.co.id</a>
+ </b>
+ </p>
+ <p style="font-size:11px; color:#777;">
+ <i>Email ini dikirim secara otomatis. Abaikan jika pembayaran telah dilakukan.</i>
+ </p>
</div>
</field>
<field name="auto_delete" eval="True"/>