From 0fe7320b3b32fa41fd06e30040171c6bf9800897 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 26 Aug 2025 09:57:51 +0700 Subject: (andri) add grand total inv --- indoteknik_custom/models/account_move.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 599b3220..6f3190f0 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -247,8 +247,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""" {inv.partner_id.name} @@ -261,6 +263,15 @@ class AccountMove(models.Model): {days_to_due} """ + invoice_table_footer = f""" + + + Grand Total + {formatLang(self.env, grand_total, currency_obj=invs[0].currency_id)} + + + + """ days_to_due_message = "" closing_message = "" @@ -302,7 +313,7 @@ class AccountMove(models.Model): body_html = re.sub( r"]*>.*?", - f"{invoice_table_rows}", + f"{invoice_table_rows}{invoice_table_footer}", template.body_html, flags=re.DOTALL ).replace('${object.name}', partner.name) \ @@ -323,16 +334,16 @@ class AccountMove(models.Model): # Siapkan email values values = { 'subject': f"Reminder Invoice Due - {partner.name}", - # 'email_to': 'andrifebriyadiputra@gmail.com', - 'email_to': email_to, + 'email_to': 'andrifebriyadiputra@gmail.com', + # 'email_to': email_to, 'email_from': 'finance@indoteknik.co.id', - 'email_cc': ",".join(sorted(set(cc_list))), + # 'email_cc': ",".join(sorted(set(cc_list))), 'body_html': body_html, - 'reply_to': 'finance@indoteknik.co.id', + # 'reply_to': 'finance@indoteknik.co.id', } - # template.send_mail(invs[0].id, force_send=True, email_values=values) - _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") + template.send_mail(invs[0].id, force_send=True, email_values=values) + # _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})") # flag invs.write({'reminder_sent_date': today}) -- cgit v1.2.3 From bb75985009a318cbbe9c4410806e06ed07aae6d1 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 26 Aug 2025 13:58:48 +0700 Subject: (andri) add limit berdasarkan blocking amount dan limit terpakai berdasarkan total amount invoices yang ada --- indoteknik_custom/models/account_move.py | 25 +++++++++++++++++++++++-- 1 file 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): """ + 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""" +

Informasi Tambahan:

+
    +
  • Total Limit: {formatLang(self.env, blocking_limit, currency_obj=currency)}
  • +
  • Total Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)}
  • +
+ """ + 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', -- cgit v1.2.3 From 43049cea86883ffcfb6ae988dc46b74ad38def85 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Tue, 26 Aug 2025 17:05:58 +0700 Subject: (andri) fix layout mail reminder & add limit, sisa limit, limit terpakai, & jatuh tempo seperti pada tempo di webite --- indoteknik_custom/models/account_move.py | 66 ++++++++++++++++++---- .../views/mail_template_invoice_reminder.xml | 54 ++++++++++-------- 2 files changed, 85 insertions(+), 35 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""" -

Informasi Tambahan:

-
    -
  • Total Limit: {formatLang(self.env, blocking_limit, currency_obj=currency)}
  • -
  • Total Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)}
  • -
+ + + + + + + + + + + + + + + +
+ Pembayaran Tempo +
+

Kredit Limit Anda
+ {formatLang(self.env, blocking_limit, currency_obj=currency)} +

+

Status Detail Tempo Pembayaran Anda
+ {partner.property_payment_term_id.name or 'Review'} +

+
+
+ {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} +
+
Sisa Kredit Limit
+
+
+ {formatLang(self.env, outstanding_amount, currency_obj=currency)} +
+
Kredit Limit Terpakai
+
{len(outstanding_invoices)} Transaksi
+
+
+ {formatLang(self.env, overdue_amount, currency_obj=currency)} +
+
Jatuh Tempo
+
{len(overdue_invoices)} Invoice
+
""" 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', diff --git a/indoteknik_custom/views/mail_template_invoice_reminder.xml b/indoteknik_custom/views/mail_template_invoice_reminder.xml index 8450be28..3a02fa2e 100644 --- a/indoteknik_custom/views/mail_template_invoice_reminder.xml +++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml @@ -8,45 +8,49 @@ finance@indoteknik.co.id -
+

Dear ${object.name},

${days_to_due_message}

- +
- - - - - - - - - + + + + + + + + + +
CustomerNo. POInvoice NumberInvoice DateDue DateAmountTermDays To Due
CustomerNo. POInvoice NumberInvoice DateDue DateAmountTermDays To Due

${closing_message}


Terima Kasih.

-
-
-

Best Regards, -
-
- Widya R.
- Dept. Finance
- PT. INDOTEKNIK DOTCOM GEMILANG
- Indoteknik
- +62-857-1697-0374 | - finance@indoteknik.co.id -

-

Email ini dikirim secara otomatis. Abaikan jika pembayaran telah dilakukan.

- +

+

+ + Best Regards,

+ Widya R.
+ Dept. Finance
+ PT. INDOTEKNIK DOTCOM GEMILANG
+ Indoteknik
+ +62-857-1697-0374 | + finance@indoteknik.co.id +
+

+

+ Email ini dikirim secara otomatis. Abaikan jika pembayaran telah dilakukan. +

-- cgit v1.2.3 From 9b0ce82de8518012198f526737403648f94d21c7 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 27 Aug 2025 16:05:55 +0700 Subject: (andri) test --- indoteknik_custom/models/account_move.py | 70 +++++++--------------- .../views/mail_template_invoice_reminder.xml | 1 + 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index d9d15764..b97edd0a 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -179,7 +179,8 @@ 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' , [14709]) ], limit=5) _logger.info(f"Invoices: {invoices}") @@ -295,48 +296,22 @@ class AccountMove(models.Model): currency = invs[0].currency_id if invs else partner.company_id.currency_id limit_info_html = f""" - - - - - - - - - - - - - - - -
- Pembayaran Tempo -
-

Kredit Limit Anda
- {formatLang(self.env, blocking_limit, currency_obj=currency)} -

-

Status Detail Tempo Pembayaran Anda
- {partner.property_payment_term_id.name or 'Review'} -

-
-
- {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} -
-
Sisa Kredit Limit
-
-
- {formatLang(self.env, outstanding_amount, currency_obj=currency)} -
-
Kredit Limit Terpakai
-
{len(outstanding_invoices)} Transaksi
-
-
- {formatLang(self.env, overdue_amount, currency_obj=currency)} -
-
Jatuh Tempo
-
{len(overdue_invoices)} Invoice
-
+

Informasi Tambahan:

+
    +
  • Kredit Limit Anda: {formatLang(self.env, blocking_limit, currency_obj=currency)}
  • +
  • Status Detail Tempo: {partner.property_payment_term_id.name or 'Review'}
  • +
  • + Sisa Kredit Limit: {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} +
  • +
  • + Kredit Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)} + ({len(outstanding_invoices)} Transaksi) +
  • +
  • + Jatuh Tempo: {formatLang(self.env, overdue_amount, currency_obj=currency)} + ({len(overdue_invoices)} Invoice) +
  • +
""" days_to_due_message = "" @@ -385,7 +360,8 @@ 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}', limit_info_html + closing_message) + .replace('${closing_message}', closing_message) \ + .replace('${limit_info_html}', limit_info_html) cc_list = [ 'finance@indoteknik.co.id', @@ -408,11 +384,11 @@ class AccountMove(models.Model): # 'reply_to': 'finance@indoteknik.co.id', } - # template.send_mail(invs[0].id, force_send=True, email_values=values) - _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") + template.send_mail(invs[0].id, force_send=True, email_values=values) + # _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})") # flag - invs.write({'reminder_sent_date': today}) + # invs.write({'reminder_sent_date': today}) # Post ke chatter user_system = self.env['res.users'].browse(25) system_id = user_system.partner_id.id if user_system else False diff --git a/indoteknik_custom/views/mail_template_invoice_reminder.xml b/indoteknik_custom/views/mail_template_invoice_reminder.xml index 3a02fa2e..13c02a08 100644 --- a/indoteknik_custom/views/mail_template_invoice_reminder.xml +++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml @@ -33,6 +33,7 @@

${closing_message}

+ ${limit_info_html}

Terima Kasih.



-- cgit v1.2.3 From 4fcaaf9bc4e1e595e196437887dbe7c15acc5c41 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 28 Aug 2025 11:47:00 +0700 Subject: (andri) fix informasi tambahan dan menambahkan button cek selengkapnya --- indoteknik_custom/models/account_move.py | 45 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index b97edd0a..8e58ce6b 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -180,7 +180,7 @@ class AccountMove(models.Model): ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), ('invoice_date_due', 'in', target_dates), ('date_terima_tukar_faktur', '!=', False), - ('partner_id', 'in' , [14709]) + ('partner_id', 'in' , [94603]) ], limit=5) _logger.info(f"Invoices: {invoices}") @@ -295,23 +295,34 @@ class AccountMove(models.Model): overdue_amount = sum(overdue_invoices.mapped('amount_total')) currency = invs[0].currency_id if invs else partner.company_id.currency_id + # tempo_link = 'https://www.indoteknik.com/my/tempo' + tempo_link = 'http://localhost:2100/my/tempo' + limit_info_html = f""" -

Informasi Tambahan:

-
    -
  • Kredit Limit Anda: {formatLang(self.env, blocking_limit, currency_obj=currency)}
  • -
  • Status Detail Tempo: {partner.property_payment_term_id.name or 'Review'}
  • -
  • - Sisa Kredit Limit: {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} -
  • -
  • - Kredit Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)} - ({len(outstanding_invoices)} Transaksi) -
  • -
  • - Jatuh Tempo: {formatLang(self.env, overdue_amount, currency_obj=currency)} - ({len(overdue_invoices)} Invoice) -
  • -
+

Informasi Tambahan:

+
    +
  • Kredit Limit Anda: {formatLang(self.env, blocking_limit, currency_obj=currency)}
  • +
  • Status Detail Tempo: {partner.property_payment_term_id.name or 'Review'}
  • +
  • + Sisa Kredit Limit: {formatLang(self.env, blocking_limit - outstanding_amount, currency_obj=currency)} +
  • +
  • + Kredit Limit Terpakai: {formatLang(self.env, outstanding_amount, currency_obj=currency)} + ({len(outstanding_invoices)} Transaksi) +
  • +
  • + Jatuh Tempo: {formatLang(self.env, overdue_amount, currency_obj=currency)} + ({len(overdue_invoices)} Invoice) +
  • +
+

+ + Cek Selengkapnya + +

""" days_to_due_message = "" -- cgit v1.2.3 From 6f6c6c86d91c811984d6ce6c478f4024cd4fb3ed Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Thu, 28 Aug 2025 16:35:58 +0700 Subject: (andri) live --- indoteknik_custom/models/account_move.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 8e58ce6b..c44cad78 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -295,8 +295,8 @@ class AccountMove(models.Model): overdue_amount = sum(overdue_invoices.mapped('amount_total')) currency = invs[0].currency_id if invs else partner.company_id.currency_id - # tempo_link = 'https://www.indoteknik.com/my/tempo' - tempo_link = 'http://localhost:2100/my/tempo' + tempo_link = 'https://indoteknik.com/my/tempo' + # tempo_link = 'http://localhost:2100/my/tempo' limit_info_html = f"""

Informasi Tambahan:

@@ -386,20 +386,20 @@ class AccountMove(models.Model): # Siapkan email values values = { - 'subject': f"Reminder Invoice Due Test - {partner.name}", - 'email_to': 'andrifebriyadiputra@gmail.com', - # 'email_to': email_to, + 'subject': f"Reminder Invoice Due - {partner.name}", + # 'email_to': 'andrifebriyadiputra@gmail.com', + 'email_to': email_to, 'email_from': 'finance@indoteknik.co.id', - # 'email_cc': ",".join(sorted(set(cc_list))), + 'email_cc': ",".join(sorted(set(cc_list))), 'body_html': body_html, - # 'reply_to': 'finance@indoteknik.co.id', + 'reply_to': 'finance@indoteknik.co.id', } template.send_mail(invs[0].id, force_send=True, email_values=values) - # _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") + _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}") _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})") # flag - # invs.write({'reminder_sent_date': today}) + invs.write({'reminder_sent_date': today}) # Post ke chatter user_system = self.env['res.users'].browse(25) system_id = user_system.partner_id.id if user_system else False -- cgit v1.2.3