diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-07-09 13:42:33 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-07-09 13:42:33 +0700 |
| commit | c72db0d0fa214e6691fa9a293020e7091a9c82c2 (patch) | |
| tree | 4ee863d201b99cd7878b24fed923597d64534511 | |
| parent | 5e905a9af7f6bb928c44cad2d47f8c6e69662bd2 (diff) | |
(andri) fix invoices
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 36 | ||||
| -rw-r--r-- | indoteknik_custom/views/mail_template_invoice_reminder.xml | 43 |
2 files changed, 45 insertions, 34 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 8ef3d273..e63f4cb2 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -76,12 +76,9 @@ class AccountMove(models.Model): def send_due_invoice_reminder(self): today = fields.Date.today() - reminder_days = [-7, -3, 0, 3, 7] - target_dates = [today + timedelta(days=delta) for delta in reminder_days] - target_dates_str = [d.isoformat() for d in target_dates] # Ganti nama partner untuk test jika perlu - partner = self.env['res.partner'].search([('name', 'ilike', 'DAYA ANUGRAH MULYA')], limit=1) + partner = self.env['res.partner'].search([('name', 'ilike', 'TIRTA FRESINDO JAYA')], limit=1) if not partner: _logger.info("Partner tidak ditemukan.") return @@ -92,6 +89,7 @@ class AccountMove(models.Model): ('payment_state', 'not in', ['paid','in_payment', 'reversed']), ('invoice_date_due', '>=', today - timedelta(days=7)), ('invoice_date_due', '>=', today - timedelta(days=3)), + ('invoice_date_due', '>=', today - timedelta(days=0)), ('invoice_date_due', '<=', today + timedelta(days=3)), ('invoice_date_due', '<=', today + timedelta(days=7)), ('partner_id', '=', partner.id), @@ -115,17 +113,25 @@ class AccountMove(models.Model): # Ambil template template = self.env.ref('indoteknik_custom.mail_template_invoice_due_reminder') - for inv in invoices: - try: - # Untuk test: override ke email pribadi Anda - email_values = { - 'email_to': 'andrifebriyadiputra@gmail.com', - 'email_from': 'finance@indoteknik.co.id', - } - template.send_mail(inv.id, force_send=True, email_values=email_values) - _logger.info(f"Reminder terkirim: {inv.name} → {email_values['email_to']}") - except Exception as e: - _logger.error(f"Gagal kirim email untuk {inv.name}: {str(e)}") + try: + template.with_context(invoices=invoices).send_mail(partner.id, force_send=True, email_values={ + 'email_to': 'andrifebriyadiputra@gmail.com', # test override + }) + _logger.info(f"Reminder terkirim ke {partner.name} → {len(invoices)} invoice") + except Exception as e: + _logger.error(f"Gagal kirim email ke {partner.name}: {str(e)}") + + # for inv in invoices: + # try: + # # Untuk test: override ke email pribadi Anda + # email_values = { + # 'email_to': 'andrifebriyadiputra@gmail.com', + # 'email_from': 'finance@indoteknik.co.id', + # } + # template.send_mail(inv.id, force_send=True, email_values=email_values) + # _logger.info(f"Reminder terkirim: {inv.name} → {email_values['email_to']}") + # except Exception as e: + # _logger.error(f"Gagal kirim email untuk {inv.name}: {str(e)}") # def name_get(self): # result = [] diff --git a/indoteknik_custom/views/mail_template_invoice_reminder.xml b/indoteknik_custom/views/mail_template_invoice_reminder.xml index b19171b2..176a68ba 100644 --- a/indoteknik_custom/views/mail_template_invoice_reminder.xml +++ b/indoteknik_custom/views/mail_template_invoice_reminder.xml @@ -3,22 +3,23 @@ <data noupdate="1"> <record id="mail_template_invoice_due_reminder" model="mail.template"> <field name="name">Invoice Reminder: Due Date Notification</field> - <field name="model_id" ref="account.model_account_move"/> - <field name="subject">[Reminder] Invoice ${object.name} is Due Soon</field> + <field name="model_id" ref="base.model_res_partner"/> + <field name="subject">[Reminder] Invoice Due Summary for ${object.name}</field> <field name="email_from">finance@indoteknik.co.id</field> - <field name="reply_to">finance@indoteknik.co.id</field> <field name="email_to">andrifebriyadiputra@gmail.com</field> + <!-- <field name="email_to">${object.email|safe}</field> --> <field name="body_html" type="html"> <div style="font-family:Arial, sans-serif; font-size:14px;"> - <p>Dengan Hormat Bpk/Ibu ${object.partner_id.name},</p> + <p>Dengan Hormat Bpk/Ibu ${object.name},</p> - <p>Berikut adalah detail invoice Anda yang sudah mendekati atau telah jatuh tempo:</p> + <p>Berikut adalah daftar invoice Anda yang mendekati atau telah jatuh tempo:</p> <table border="1" cellpadding="6" cellspacing="0" style="border-collapse: collapse; width: 100%;"> <thead> <tr style="background-color: #f2f2f2;"> + <th>No</th> <th>Invoice Number</th> - <th>Tanggal Invoice</th> + <th>Tanggal</th> <th>Jatuh Tempo</th> <th>Sisa Hari</th> <th>Total</th> @@ -26,30 +27,34 @@ </tr> </thead> <tbody> - <tr> - <td>${object.name}</td> - <td>${format_date(object.invoice_date)}</td> - <td>${format_date(object.invoice_date_due)}</td> - <td>${object.invoice_day_to_due}</td> - <td>${format_amount(object.amount_total, object.currency_id)}</td> - <td>${object.ref or '-'}</td> - </tr> + <t t-set="i" t-value="1"/> + <t t-foreach="ctx.get('invoices', [])" t-as="inv"> + <tr> + <td><t t-esc="i"/></td> + <td><t t-esc="inv.name"/></td> + <td><t t-esc="format_date(inv.invoice_date)"/></td> + <td><t t-esc="format_date(inv.invoice_date_due)"/></td> + <td><t t-esc="inv.invoice_day_to_due"/></td> + <td><t t-esc="format_amount(inv.amount_total, inv.currency_id)"/></td> + <td><t t-esc="inv.ref or '-'"/></td> + </tr> + <t t-set="i" t-value="i + 1"/> + </t> </tbody> </table> - <p>Mohon segera melakukan proses pembayaran sebelum jatuh tempo.</p> - - <p>Terima kasih atas perhatian dan kerjasamanya.</p> + <p>Mohon segera melakukan proses pembayaran. Terima kasih.</p> <p> Hormat Kami,<br/> <strong>PT. INDOTEKNIK DOTCOM GEMILANG</strong><br/> - Jl. Bandengan Utara 85A No. 8-9, Penjaringan, Jakarta Utara<br/> - Telp: 021-2933 8828 / 29 | Email: finance@indoteknik.co.id + Telp: 021-2933 8828 / 29<br/> + Email: finance@indoteknik.co.id </p> </div> </field> <field name="auto_delete" eval="True"/> </record> + </data> </odoo> |
