summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-08-11 12:52:28 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-08-11 12:52:28 +0700
commit74e2ec630680c2e9a679f837bd1278a7d0a838de (patch)
tree27847ff1d4b7db09d371b4dd1b08eb96f5cea177
parentbbd7fbf19ef974b4f7716671e3d6203a15a2f2c3 (diff)
(andri) fix reminder inv
-rw-r--r--indoteknik_custom/models/account_move.py27
1 files changed, 18 insertions, 9 deletions
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"""
<tr>
<td>{inv.partner_id.name}</td>
- <td>{inv.purchase_order_id.name or '-'}</td>
+ <td>{inv.ref or '-'}</td>
<td>{inv.name}</td>
<td>{fields.Date.to_string(inv.invoice_date) or '-'}</td>
<td>{fields.Date.to_string(inv.invoice_date_due) or '-'}</td>
@@ -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'],