summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-09-30 08:09:37 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-09-30 08:09:37 +0700
commitfa8322bc30edf708252d8d932abfc0735b51951c (patch)
tree723c5e60b36dcdff7fe427b86f079157774f0591 /indoteknik_custom/models
parent1f58d7d4973edf04d6a3f3092115492585c1545b (diff)
parente87e62308f3f38f03b82e22765fa1a203a869a82 (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
merge
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/approval_payment_term.py1
-rw-r--r--indoteknik_custom/models/letter_receivable.py167
-rw-r--r--indoteknik_custom/models/stock_picking.py3
3 files changed, 104 insertions, 67 deletions
diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py
index 449bd90b..e45305db 100644
--- a/indoteknik_custom/models/approval_payment_term.py
+++ b/indoteknik_custom/models/approval_payment_term.py
@@ -56,6 +56,7 @@ class ApprovalPaymentTerm(models.Model):
change_log_688 = fields.Text(string="Change Log", readonly=True, copy=False)
+
def write(self, vals):
# Ambil nilai lama sebelum perubahan
old_values_dict = {
diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py
index 16034938..ffe14491 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,20 +230,27 @@ 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})",
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()
@@ -253,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"""
- <tr>
- <td>{line.invoice_number or '-'}</td>
- <td>{self.partner_id.name or '-'}</td>
- <td>{fields.Date.to_string(line.invoice_date) or '-'}</td>
- <td>{fields.Date.to_string(line.invoice_date_due) or '-'}</td>
- <td>{line.new_invoice_day_to_due}</td>
- <td>{line.ref or '-'}</td>
- <td>{formatLang(self.env, line.amount_residual, currency_obj=line.currency_id)}</td>
- <td>{line.payment_term_id.name or '-'}</td>
- </tr>
- """
-
- invoice_table_footer = f"""
- <tfoot>
- <tr style="font-weight:bold; background-color:#f9f9f9;">
- <td colspan="6" align="right">Grand Total</td>
- <td>{formatLang(self.env, grand_total, currency_obj=self.currency_id, monetary=True)}</td>
- <td colspan="2"></td>
+ 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"""
+ <tr>
+ <td>{line.invoice_number or '-'}</td>
+ <td>{self.partner_id.name or '-'}</td>
+ <td>{fields.Date.to_string(line.invoice_date) or '-'}</td>
+ <td>{fields.Date.to_string(line.invoice_date_due) or '-'}</td>
+ <td>{line.new_invoice_day_to_due}</td>
+ <td>{line.ref or '-'}</td>
+ <td>{formatLang(self.env, line.amount_residual, currency_obj=line.currency_id)}</td>
+ <td>{line.payment_term_id.name or '-'}</td>
</tr>
- </tfoot>
- """
- # inject table rows ke template
- body_html = re.sub(
- r"<tbody[^>]*>.*?</tbody>",
- f"<tbody>{invoice_table_rows}</tbody>{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"""
+ <tfoot>
+ <tr style="font-weight:bold; background-color:#f9f9f9;">
+ <td colspan="6" align="right">Grand Total</td>
+ <td>{formatLang(self.env, grand_total, currency_obj=self.currency_id, monetary=True)}</td>
+ <td colspan="2"></td>
+ </tr>
+ </tfoot>
+ """
+
+ body_html = re.sub(
+ r"<tbody[^>]*>.*?</tbody>",
+ f"<tbody>{invoice_table_rows}</tbody>{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)
@@ -335,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(
@@ -352,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."
)
@@ -453,6 +476,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 +497,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"
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 51f4cccd..16e235da 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -153,6 +153,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.")
@@ -394,7 +395,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!")
)