From 7965212570e382b1fe94a96cfe16f3d2babb1d27 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 22 Sep 2025 09:53:47 +0700 Subject: (andri) init button --- indoteknik_custom/models/approval_payment_term.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index 449bd90b..fbdabe7f 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -56,6 +56,10 @@ class ApprovalPaymentTerm(models.Model): change_log_688 = fields.Text(string="Change Log", readonly=True, copy=False) + def button_closing_mail(self): + + return + def write(self, vals): # Ambil nilai lama sebelum perubahan old_values_dict = { -- cgit v1.2.3 From d32684d5d69a76c97ac962e898f3bb58f708fca4 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Thu, 25 Sep 2025 11:06:24 +0700 Subject: (andri) penambahan perihal penutupan tempo pada surat piutang --- indoteknik_custom/models/letter_receivable.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py index 16034938..6f95e5e7 100644 --- a/indoteknik_custom/models/letter_receivable.py +++ b/indoteknik_custom/models/letter_receivable.py @@ -23,6 +23,7 @@ class SuratPiutang(models.Model): tujuan_nama = fields.Char(string="Nama Tujuan", tracking=True) tujuan_email = fields.Char(string="Email Tujuan", tracking=True) perihal = fields.Selection([ + ('tutup_tempo', 'Surat Penutupan Pembayaran Tempo'), ('penagihan', 'Surat Resmi Penagihan'), ('sp1', 'Surat Peringatan Piutang ke-1'), ('sp2', 'Surat Peringatan Piutang ke-2'), @@ -36,6 +37,7 @@ class SuratPiutang(models.Model): ("sent", "Approved & Sent") ], default="draft", tracking=True) send_date = fields.Datetime(string="Tanggal Kirim", tracking=True) + due_date = fields.Date(string="Tanggal Jatuh Tempo", tracking=True, default= fields.Date.today) seven_days_after_sent_date = fields.Char(string="7 Hari Setelah Tanggal Kirim") periode_invoices_terpilih = fields.Char( string="Periode Invoices Terpilih", @@ -228,14 +230,14 @@ class SuratPiutang(models.Model): continue # === Surat penagihan biasa (langsung Pimpinan approve) === - if rec.perihal == "penagihan": + if rec.perihal in ("tutup_tempo", "penagihan"): # if self.env.user.id not in pimpinan_user_ids: # raise UserError("Hanya Pimpinan yang boleh menyetujui surat penagihan.") rec.state = "sent" now_utc = now_wib.astimezone(pytz.UTC).replace(tzinfo=None) rec.send_date = now_utc rec.action_send_letter() - rec.message_post(body="Surat Penagihan disetujui dan berhasil dikirim.") + rec.message_post(body=f"{rec.perihal_label} disetujui dan berhasil dikirim.") self.env.user.notify_info( message=f"Surat piutang {rec.name} berhasil dikirim ke {rec.partner_id.name} ({rec.tujuan_email})", @@ -453,6 +455,18 @@ class SuratPiutang(models.Model): body=f"Line Invoices diperbarui. Total line saat ini: {len(rec.line_ids)}" ) + @api.onchange('perihal', 'partner_id') + def _onchange_perihal_tutup_tempo(self): + if self.perihal == 'tutup_tempo': + for line in self.line_ids: + if line.new_invoice_day_to_due < -30: + line.selected = True + else: + line.selected = False + else: + for line in self.line_ids: + line.selected = False + @api.model def create(self, vals): # Generate nomor surat otomatis @@ -462,7 +476,7 @@ class SuratPiutang(models.Model): bulan_romawi = ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"][today.month-1] tahun = today.strftime("%y") vals["name"] = f"{seq}/LO/FAT/IDG/{bulan_romawi}/{tahun}" - if vals.get("perihal") == "penagihan": + if vals.get("perihal") in ("tutup_tempo", "penagihan"): vals["state"] = "waiting_approval_pimpinan" else: vals["state"] = "waiting_approval_sales" -- cgit v1.2.3 From 1b574687a7f4b612a1fd221da1ca920009cc963b Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Thu, 25 Sep 2025 14:33:51 +0700 Subject: (andri) make report & mail template close tempo --- indoteknik_custom/models/letter_receivable.py | 145 +++++++++++++++----------- 1 file changed, 83 insertions(+), 62 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py index 6f95e5e7..bfa1e966 100644 --- a/indoteknik_custom/models/letter_receivable.py +++ b/indoteknik_custom/models/letter_receivable.py @@ -244,6 +244,13 @@ class SuratPiutang(models.Model): title="Informasi", sticky=False ) + + def action_print(self): + self.ensure_one() + if self.perihal == 'tutup_tempo': + return self.env.ref('indoteknik_custom.action_report_surat_tutup_tempo').report_action(self) + else: + return self.env.ref('indoteknik_custom.action_report_surat_piutang').report_action(self) def action_send_letter(self): self.ensure_one() @@ -255,64 +262,79 @@ class SuratPiutang(models.Model): if not self.tujuan_email: raise UserError(_("Email tujuan harus diisi.")) - template = self.env.ref('indoteknik_custom.letter_receivable_mail_template') - # today = fields.Date.today() - - month_map = { - 1: "Januari", 2: "Februari", 3: "Maret", 4: "April", - 5: "Mei", 6: "Juni", 7: "Juli", 8: "Agustus", - 9: "September", 10: "Oktober", 11: "November", 12: "Desember", - } - target_date = (self.send_date or fields.Datetime.now()).date() + timedelta(days=7) - self.seven_days_after_sent_date = f"{target_date.day} {month_map[target_date.month]}" - - perihal_map = { - 'penagihan': 'Surat Resmi Penagihan', - 'sp1': 'Surat Peringatan Pertama (I)', - 'sp2': 'Surat Peringatan Kedua (II)', - 'sp3': 'Surat Peringatan Ketiga (III)', - } - perihal_text = perihal_map.get(self.perihal, self.perihal or '') - - invoice_table_rows = "" - grand_total = 0 - for line in selected_lines: - # days_to_due = (line.invoice_date_due - today).days if line.invoice_date_due else 0 - grand_total += line.amount_residual - invoice_table_rows += f""" - - {line.invoice_number or '-'} - {self.partner_id.name or '-'} - {fields.Date.to_string(line.invoice_date) or '-'} - {fields.Date.to_string(line.invoice_date_due) or '-'} - {line.new_invoice_day_to_due} - {line.ref or '-'} - {formatLang(self.env, line.amount_residual, currency_obj=line.currency_id)} - {line.payment_term_id.name or '-'} - - """ - - invoice_table_footer = f""" - - - Grand Total - {formatLang(self.env, grand_total, currency_obj=self.currency_id, monetary=True)} - + template = None + report = None + body_html = None + subject = None + + # Logika untuk memilih template dan report berdasarkan 'perihal' + if self.perihal == 'tutup_tempo': + template = self.env.ref('indoteknik_custom.close_tempo_mail_template') + report = self.env.ref('indoteknik_custom.action_report_surat_tutup_tempo') + due_date_str = self.due_date.strftime('%d %B %Y') if self.due_date else 'yang telah ditentukan' + body_html = template.body_html \ + .replace('${object.partner_id.name}', self.partner_id.name or '') \ + .replace('${object.due_date}', due_date_str or '') + subject = f"Pemberitahuan Penutupan Pembayaran Tempo – {self.partner_id.name}" + else: + template = self.env.ref('indoteknik_custom.letter_receivable_mail_template') + + month_map = { + 1: "Januari", 2: "Februari", 3: "Maret", 4: "April", + 5: "Mei", 6: "Juni", 7: "Juli", 8: "Agustus", + 9: "September", 10: "Oktober", 11: "November", 12: "Desember", + } + target_date = (self.send_date or fields.Datetime.now()).date() + timedelta(days=7) + self.seven_days_after_sent_date = f"{target_date.day} {month_map[target_date.month]}" + + perihal_map = { + 'penagihan': 'Surat Resmi Penagihan', + 'sp1': 'Surat Peringatan Pertama (I)', + 'sp2': 'Surat Peringatan Kedua (II)', + 'sp3': 'Surat Peringatan Ketiga (III)', + } + perihal_text = perihal_map.get(self.perihal, self.perihal or '') + + invoice_table_rows = "" + grand_total = 0 + for line in selected_lines: + grand_total += line.amount_residual + invoice_table_rows += f""" + + {line.invoice_number or '-'} + {self.partner_id.name or '-'} + {fields.Date.to_string(line.invoice_date) or '-'} + {fields.Date.to_string(line.invoice_date_due) or '-'} + {line.new_invoice_day_to_due} + {line.ref or '-'} + {formatLang(self.env, line.amount_residual, currency_obj=line.currency_id)} + {line.payment_term_id.name or '-'} - - """ - # inject table rows ke template - body_html = re.sub( - r"]*>.*?", - f"{invoice_table_rows}{invoice_table_footer}", - template.body_html, - flags=re.DOTALL - ).replace('${object.name}', self.name or '') \ - .replace('${object.partner_id.name}', self.partner_id.name or '') \ - .replace('${object.seven_days_after_sent_date}', self.seven_days_after_sent_date or '') \ - .replace('${object.perihal}', perihal_text or '') - - report = self.env.ref('indoteknik_custom.action_report_surat_piutang') + """ + + invoice_table_footer = f""" + + + Grand Total + {formatLang(self.env, grand_total, currency_obj=self.currency_id, monetary=True)} + + + + """ + + body_html = re.sub( + r"]*>.*?", + f"{invoice_table_rows}{invoice_table_footer}", + template.body_html, + flags=re.DOTALL + ).replace('${object.name}', self.name or '') \ + .replace('${object.partner_id.name}', self.partner_id.name or '') \ + .replace('${object.seven_days_after_sent_date}', self.seven_days_after_sent_date or '') \ + .replace('${object.perihal}', perihal_text or '') + + report = self.env.ref('indoteknik_custom.action_report_surat_piutang') + subject = perihal_map.get(self.perihal, self.perihal or '') + " - " + (self.partner_id.name or '') + pdf_content, _ = report._render_qweb_pdf([self.id]) attachment_base64 = base64.b64encode(pdf_content) @@ -337,14 +359,13 @@ class SuratPiutang(models.Model): cc_list.append(sales_email) values = { - # 'subject': template.subject.replace('${object.name}', self.name or ''), - 'subject': perihal_map.get(self.perihal, self.perihal or '') + " - " + (self.partner_id.name or ''), + 'subject': subject, # Menggunakan subject yang sudah ditentukan di atas 'email_to': self.tujuan_email, 'email_from': 'finance@indoteknik.co.id', - 'email_cc': ",".join(sorted(set(cc_list))), - 'body_html': body_html, + # 'email_cc': ",".join(sorted(set(cc_list))), + 'body_html': body_html, # Menggunakan body_html yang sudah ditentukan di atas 'attachments': [(attachment.name, attachment.datas)], - 'reply_to': 'finance@indoteknik.co.id', + # 'reply_to': 'finance@indoteknik.co.id', } template.with_context(mail_post_autofollow=False).send_mail( -- cgit v1.2.3 From 31a22f2f26b29f91bd43ea48ce84e8dc9aaf3c12 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Thu, 25 Sep 2025 15:35:43 +0700 Subject: fix --- indoteknik_custom/models/letter_receivable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py index bfa1e966..ffe14491 100644 --- a/indoteknik_custom/models/letter_receivable.py +++ b/indoteknik_custom/models/letter_receivable.py @@ -375,7 +375,7 @@ class SuratPiutang(models.Model): ) _logger.info( - f"Surat Piutang {self.name} terkirim ke {self.tujuan_email} " + f"{self.name} terkirim ke {self.tujuan_email} " f"({self.partner_id.name}), total {len(selected_lines)} invoice." ) -- cgit v1.2.3 From 6239b00631bd709557349d8d3635001659b83d93 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 29 Sep 2025 15:17:43 +0700 Subject: push --- indoteknik_custom/models/stock_picking.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index b27e6b5d..ae4f64a8 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -152,6 +152,7 @@ class StockPicking(models.Model): state_reserve = fields.Selection([ ('waiting', 'Waiting For Fullfilment'), ('ready', 'Ready to Ship'), + ('partial', 'Ready to Ship Partial'), ('done', 'Done'), ('cancel', 'Cancelled'), ], string='Status Reserve', tracking=True, copy=False, help="The current state of the stock picking.") @@ -393,7 +394,7 @@ class StockPicking(models.Model): deadline = kirim_date + timedelta(days=1) deadline = deadline.replace(hour=10, minute=0, second=0) - if now > deadline: + if now > deadline and not self.so_lama: raise ValidationError( _("Anda tidak dapat mengubah Tanggal Kirim setelah jam 10:00 pada hari berikutnya!") ) -- cgit v1.2.3 From a66344ded40391a3a2591581141d2d44ed1ad712 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 29 Sep 2025 16:07:26 +0700 Subject: (andri) del --- indoteknik_custom/models/approval_payment_term.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py index fbdabe7f..e45305db 100644 --- a/indoteknik_custom/models/approval_payment_term.py +++ b/indoteknik_custom/models/approval_payment_term.py @@ -56,9 +56,6 @@ class ApprovalPaymentTerm(models.Model): change_log_688 = fields.Text(string="Change Log", readonly=True, copy=False) - def button_closing_mail(self): - - return def write(self, vals): # Ambil nilai lama sebelum perubahan -- cgit v1.2.3