From 7a329ad669cb9fe630a52651a438f9bb5f294c40 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 11 Aug 2025 08:33:26 +0700 Subject: (andri) fix reminder --- indoteknik_custom/models/account_move.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index fd08ed60..7a331791 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -190,11 +190,16 @@ class AccountMove(models.Model): ]) _logger.info(f"Email Reminder Child {reminder_contacts}") - if not reminder_contacts: - _logger.info(f"Partner {partner.name} tidak memiliki email yang sudah ceklis reminder") - continue + # if not reminder_contacts: + # _logger.info(f"Partner {partner.name} tidak memiliki email yang sudah ceklis reminder") + # continue emails = list(filter(None, [partner.email])) + reminder_contacts.mapped('email') + if reminder_contacts: + _logger.info(f"Email Reminder Child {reminder_contacts}") + else: + _logger.info(f"Tidak ada child contact reminder, gunakan email utama partner") + if not emails: _logger.info(f"Partner {partner.name} tidak memiliki email yang bisa dikirimi") continue -- cgit v1.2.3 From 74e2ec630680c2e9a679f837bd1278a7d0a838de Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 11 Aug 2025 12:52:28 +0700 Subject: (andri) fix reminder inv --- indoteknik_custom/models/account_move.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 7a331791..85ded4cd 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -97,6 +97,8 @@ class AccountMove(models.Model): payment_date = fields.Date(string="Payment Date", compute='_compute_payment_date') partial_payment = fields.Float(string="Partial Payment", compute='compute_partial_payment') + reminder_sent_date = fields.Date(string="Tanggal Reminder Terkirim") + def compute_partial_payment(self): for move in self: if move.amount_total_signed > 0 and move.amount_residual_signed > 0 and move.payment_state == 'partial': @@ -177,11 +179,18 @@ class AccountMove(models.Model): invoice_group = {} for inv in invoices: dtd = (inv.invoice_date_due - today).days if inv.invoice_date_due else 0 - invoice_group.setdefault((inv.partner_id, dtd), []).append(inv) + key = (inv.partner_id, dtd) + if key not in invoice_group: + invoice_group[key] = self.env['account.move'] # recordset kosong + invoice_group[key] |= inv # gabung recordset template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') for (partner, dtd), invs in invoice_group.items(): + if all(inv.reminder_sent_date == today for inv in invs): + _logger.info(f"Reminder untuk {partner.name} sudah terkirim hari ini, skip.") + continue + # Ambil child contact yang di-checklist reminder_invoices reminder_contacts = self.env['res.partner'].search([ ('parent_id', '=', partner.id), @@ -213,7 +222,7 @@ class AccountMove(models.Model): invoice_table_rows += f""" {inv.partner_id.name} - {inv.purchase_order_id.name or '-'} + {inv.ref or '-'} {inv.name} {fields.Date.to_string(inv.invoice_date) or '-'} {fields.Date.to_string(inv.invoice_date_due) or '-'} @@ -225,9 +234,9 @@ class AccountMove(models.Model): days_to_due_message = "" closing_message = "" - if dtd < 0: + if dtd > 0: days_to_due_message = ( - f"Kami ingin mengingatkan bahwa tagihan anda akan jatuh tempo dalam {abs(dtd)} hari ke depan, " + f"Kami ingin mengingatkan bahwa tagihan anda akan jatuh tempo dalam {dtd} hari ke depan, " "dengan rincian sebagai berikut:" ) closing_message = ( @@ -249,9 +258,9 @@ class AccountMove(models.Model): "Terima kasih atas perhatian dan kerja samanya." ) - if dtd > 0: + if dtd < 0: days_to_due_message = ( - f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {dtd} hari, " + f"Kami ingin mengingatkan bahwa tagihan anda telah jatuh tempo selama {abs(dtd)} hari, " "dengan rincian sebagai berikut:" ) closing_message = ( @@ -292,13 +301,13 @@ class AccountMove(models.Model): 'reply_to': 'finance@indoteknik.co.id', } - _logger.info(f"Mengirim email ke: {values['email_to']} CC: {values['email_cc']}") + _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) - + # flag + 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 - for inv in invs: inv.message_post( subject=values['subject'], -- cgit v1.2.3 From 8cda2bffdae2ad10c32421958e0114a5f3a9d6e1 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 11 Aug 2025 12:54:54 +0700 Subject: (andri) fix --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 85ded4cd..273bcdf9 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -296,7 +296,7 @@ class AccountMove(models.Model): # 'email_to': 'andrifebriyadiputra@gmail.com', 'email_to': email_to, 'email_from': 'finance@indoteknik.co.id', - 'email_cc': ",".join(cc_list), + 'email_cc': ",".join(sorted(set(cc_list))), 'body_html': body_html, 'reply_to': 'finance@indoteknik.co.id', } -- cgit v1.2.3 From 1a0f0657125831bd9dae86b12e7e2b13528b3d14 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 13 Aug 2025 16:02:59 +0700 Subject: (andri) add filter date terima faktur & reminder kelipatan 7 jika sudah lewat dari H+7 --- indoteknik_custom/models/account_move.py | 33 +++++--------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) (limited to 'indoteknik_custom/models/account_move.py') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 273bcdf9..b0ffd8b9 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -121,20 +121,6 @@ class AccountMove(models.Model): else: move.payment_date = False - # def name_get(self): - # result = [] - # for move in self: - # if move.move_type == 'entry': - # # Jika masih draft, tampilkan 'Draft CAB' - # if move.state == 'draft': - # label = 'Draft CAB' - # else: - # label = move.name - # result.append((move.id, label)) - # else: - # # Untuk invoice dan lainnya, pakai default - # result.append((move.id, move.display_name)) - # return result def send_due_invoice_reminder(self): today = fields.Date.today() @@ -146,31 +132,22 @@ class AccountMove(models.Model): today + timedelta(days=7), ] - # --- TESTING --- - # partner = self.env['res.partner'].search([('name', 'ilike', 'DIRGANTARA YUDHA ARTHA')], limit=1) - # if not partner: - # _logger.info("Partner tidak ditemukan.") - # return - # invoices = self.env['account.move'].search([ - # ('move_type', '=', 'out_invoice'), - # ('state', '=', 'posted'), - # ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), - # ('invoice_date_due', 'in', target_dates), - # ('partner_id', '=', partner.id), - # ]) + for days_after_due in range(14, 181, 7): + target_dates.append(today - timedelta(days=days_after_due)) invoices = self.env['account.move'].search([ ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), ('payment_state', 'not in', ['paid', 'in_payment', 'reversed']), ('invoice_date_due', 'in', target_dates), + ('date_terima_tukar_faktur', '!=', False) ]) - _logger.info(f"Invoices tahap 1: {invoices}") + _logger.info(f"Invoices: {invoices}") invoices = invoices.filtered( lambda inv: inv.invoice_payment_term_id and 'tempo' in (inv.invoice_payment_term_id.name or '').lower() ) - _logger.info(f"Invoices tahap 2: {invoices}") + # _logger.info(f"Invoices tahap 2: {invoices}") if not invoices: _logger.info("Tidak ada invoice yang due") -- cgit v1.2.3