diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-08-26 17:05:58 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-08-26 17:05:58 +0700 |
| commit | 43049cea86883ffcfb6ae988dc46b74ad38def85 (patch) | |
| tree | 4216b3bdc73e9c8099066d383e0efb367d267d1e /indoteknik_custom/models | |
| parent | bb75985009a318cbbe9c4410806e06ed07aae6d1 (diff) | |
(andri) fix layout mail reminder & add limit, sisa limit, limit terpakai, & jatuh tempo seperti pada tempo di webite
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 49bfe762..f5dd5a39 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) - ], limit=5) + ('date_terima_tukar_faktur', '!=', False), + ('partner_id', 'in', [88813, 80163]) + ]) _logger.info(f"Invoices: {invoices}") invoices = invoices.filtered( @@ -275,23 +276,68 @@ class AccountMove(models.Model): 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') - ]) - _logger.info(f"Outstanding invoices for {partner.name}: {outstanding_invoices}") + 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 limit_info_html = f""" - <p><b>Informasi Tambahan:</b></p> - <ul> - <li>Total Limit: {formatLang(self.env, blocking_limit, currency_obj=currency)}</li> - <li>Total Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)}</li> - </ul> + <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:600px; border:1px solid #ddd; border-radius:8px; font-family:Arial, sans-serif; margin:20px 0;"> + <tr> + <td colspan="3" style="background-color:#f5f5f5; padding:10px; font-size:12px; font-weight:bold; text-align:center; color:#333; border-bottom:1px solid #ddd;"> + Pembayaran Tempo + </td> + </tr> + <tr> + <td colspan="3" style="padding:15px; font-size:10px; color:#333;"> + <p style="margin:4px 0;"><b>Kredit Limit Anda</b><br/> + {formatLang(self.env, blocking_limit, currency_obj=currency)} + </p> + <p style="margin:4px 0;"><b>Status Detail Tempo Pembayaran Anda</b><br/> + {partner.property_payment_term_id.name or 'Review'} + </p> + </td> + </tr> + <tr> + <!-- Sisa Kredit Limit --> + <td style="width:33%; border-top:1px solid #ddd; padding:12px; text-align:center; font-size:10px; color:#333;"> + <div style="font-weight:bold; color:{'red' if (blocking_limit - outstanding_amount) < 0 else 'green'};"> + {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} + </div> + <div style="font-size:10px; opacity:0.8;">Sisa Kredit Limit</div> + </td> + <!-- Kredit Limit Terpakai --> + <td style="width:33%; border-left:1px solid #ddd; border-top:1px solid #ddd; padding:12px; text-align:center; font-size:10px; color:#333;"> + <div style="font-weight:bold; color:red;"> + {formatLang(self.env, outstanding_amount, currency_obj=currency)} + </div> + <div style="font-size:10px; opacity:0.8;">Kredit Limit Terpakai</div> + <div style="font-size:9px; color:#666;">{len(outstanding_invoices)} Transaksi</div> + </td> + <!-- Jatuh Tempo --> + <td style="width:33%; border-left:1px solid #ddd; border-top:1px solid #ddd; padding:12px; text-align:center; font-size:10px; color:#333;"> + <div style="font-weight:bold; color:red;"> + {formatLang(self.env, overdue_amount, currency_obj=currency)} + </div> + <div style="font-size:10px; opacity:0.8;">Jatuh Tempo</div> + <div style="font-size:9px; color:#666;">{len(overdue_invoices)} Invoice</div> + </td> + </tr> + </table> """ days_to_due_message = "" @@ -340,7 +386,7 @@ class AccountMove(models.Model): ).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 + limit_info_html) + .replace('${closing_message}', limit_info_html + closing_message) cc_list = [ 'finance@indoteknik.co.id', |
