summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-08-26 13:58:48 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-08-26 13:58:48 +0700
commitbb75985009a318cbbe9c4410806e06ed07aae6d1 (patch)
treec265cf9a80576416caa2fbe3ec15baf836dce17d
parent0fe7320b3b32fa41fd06e30040171c6bf9800897 (diff)
(andri) add limit berdasarkan blocking amount dan limit terpakai berdasarkan total amount invoices yang ada
-rw-r--r--indoteknik_custom/models/account_move.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 6f3190f0..49bfe762 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -273,6 +273,27 @@ class AccountMove(models.Model):
</tfoot>
"""
+ blocking_limit = partner.blocking_stage or 0.0
+
+ 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'))
+ 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>
+ """
+
days_to_due_message = ""
closing_message = ""
if dtd > 0:
@@ -319,7 +340,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)
+ .replace('${closing_message}', closing_message + limit_info_html)
cc_list = [
'finance@indoteknik.co.id',
@@ -333,7 +354,7 @@ class AccountMove(models.Model):
# Siapkan email values
values = {
- 'subject': f"Reminder Invoice Due - {partner.name}",
+ 'subject': f"Reminder Invoice Due Test - {partner.name}",
'email_to': 'andrifebriyadiputra@gmail.com',
# 'email_to': email_to,
'email_from': 'finance@indoteknik.co.id',