diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-08-28 09:38:36 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-08-28 09:38:36 +0000 |
| commit | 0112ac064a7484685119cf9371ffbea32de6fd59 (patch) | |
| tree | 69ba30254539ecb1e881a887e04bf0537ba461c5 /indoteknik_custom/models | |
| parent | 26623e1b2e8ba83367814ac704fbb19a4370f56c (diff) | |
| parent | 6f6c6c86d91c811984d6ce6c478f4024cd4fb3ed (diff) | |
Merged in reminder-tempo-v2 (pull request #394)
Reminder tempo v2
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 72 |
1 files changed, 68 insertions, 4 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', |
