summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-09-17 11:27:47 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-09-17 11:27:47 +0000
commit1fdeef8073eb35b407bb0b3cdb26bf635b3b1629 (patch)
tree9c423f561f8929bdeee06ed707d2e08da9c3f246
parentef9daab07049de822b7137b4a9a5d3f1fba53992 (diff)
parent886c28f6ebf20dcca5252341a8f6b61cd4d89d71 (diff)
Merged in form-sp (pull request #423)
Form sp
-rwxr-xr-xindoteknik_custom/__manifest__.py4
-rwxr-xr-xindoteknik_custom/models/__init__.py4
-rw-r--r--indoteknik_custom/models/account_move.py15
-rw-r--r--indoteknik_custom/models/letter_receivable.py496
-rw-r--r--indoteknik_custom/models/unpaid_invoice_view.py55
-rw-r--r--indoteknik_custom/report/report_surat_piutang copy.xml149
-rw-r--r--indoteknik_custom/report/report_surat_piutang.xml241
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv5
-rw-r--r--indoteknik_custom/views/ir_sequence.xml9
-rw-r--r--indoteknik_custom/views/letter_receivable.xml190
-rw-r--r--indoteknik_custom/views/letter_receivable_mail_template.xml77
-rw-r--r--indoteknik_custom/views/unpaid_invoice_view.xml96
12 files changed, 1331 insertions, 10 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 791f77f6..cf7cf1e4 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -166,6 +166,7 @@
'report/report_invoice.xml',
'report/report_picking.xml',
'report/report_sale_order.xml',
+ 'report/report_surat_piutang.xml',
'report/purchase_report.xml',
'views/vendor_sla.xml',
'views/coretax_faktur.xml',
@@ -178,6 +179,9 @@
'views/tukar_guling_po.xml',
# 'views/refund_sale_order.xml',
'views/update_date_planned_po_wizard_view.xml',
+ 'views/unpaid_invoice_view.xml',
+ 'views/letter_receivable.xml',
+ 'views/letter_receivable_mail_template.xml',
# 'views/reimburse.xml',
'views/sj_tele.xml'
],
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index c0aa7085..6dc61277 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -157,4 +157,6 @@ from . import refund_sale_order
from . import tukar_guling
from . import tukar_guling_po
from . import update_date_planned_po_wizard
-from . import sj_tele \ No newline at end of file
+from . import unpaid_invoice_view
+from . import letter_receivable
+from . import sj_tele
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index f10ca23f..ec23c626 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -218,8 +218,7 @@ class AccountMove(models.Model):
('payment_state', 'not in', ['paid', 'in_payment', 'reversed']),
('invoice_date_due', '<', today),
('date_terima_tukar_faktur', '!=', False),
- ('invoice_payment_term_id.name', 'ilike', 'tempo'),
- ('partner_id', 'in', [94603])])
+ ('invoice_payment_term_id.name', 'ilike', 'tempo')])
_logger.info(f"Found {len(invoices)} invoices overdue for reminder {invoices}.")
if not invoices:
_logger.info("Tidak ada invoice yang overdue")
@@ -423,20 +422,20 @@ class AccountMove(models.Model):
# Siapkan email values
values = {
- 'subject': f"Reminder Invoice Due Test - {partner.name}",
+ 'subject': f"Reminder Invoice Due - {partner.name}",
'email_to': 'andrifebriyadiputra@gmail.com',
- # 'email_to': email_to,
+ 'email_to': email_to,
'email_from': 'finance@indoteknik.co.id',
- # 'email_cc': ",".join(sorted(set(cc_list))),
+ 'email_cc': ",".join(sorted(set(cc_list))),
'body_html': body_html,
- # 'reply_to': 'finance@indoteknik.co.id',
+ 'reply_to': 'finance@indoteknik.co.id',
}
template.send_mail(invs[0].id, force_send=True, email_values=values)
- # _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}")
+ _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}")
_logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})")
# flag
- # invs.write({'reminder_sent_date': today})
+ 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
diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py
new file mode 100644
index 00000000..1445800f
--- /dev/null
+++ b/indoteknik_custom/models/letter_receivable.py
@@ -0,0 +1,496 @@
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError
+from odoo.exceptions import ValidationError
+from odoo.tools import mail, formatLang
+from terbilang import Terbilang
+import re
+import logging
+from datetime import datetime, timedelta
+import babel
+import base64
+import pytz
+
+_logger = logging.getLogger(__name__)
+
+class SuratPiutang(models.Model):
+ _name = "surat.piutang"
+ _description = "Surat Piutang"
+ _inherit = ['mail.thread', 'mail.activity.mixin']
+ _order = 'name desc'
+
+ name = fields.Char(string="Nomor Surat", readonly=True, copy=False)
+ partner_id = fields.Many2one("res.partner", string="Customer", required=True, tracking=True)
+ tujuan_nama = fields.Char(string="Nama Tujuan", tracking=True)
+ tujuan_email = fields.Char(string="Email Tujuan", tracking=True)
+ perihal = fields.Selection([
+ ('penagihan', 'Surat Resmi Penagihan'),
+ ('sp1', 'Surat Peringatan Piutang ke-1'),
+ ('sp2', 'Surat Peringatan Piutang ke-2'),
+ ('sp3', 'Surat Peringatan Piutang ke-3')
+ ], string="Perihal", required=True, tracking=True)
+ line_ids = fields.One2many("surat.piutang.line", "surat_id", string="Invoice Lines")
+ state = fields.Selection([
+ ("draft", "Draft"),
+ ("waiting_approval_sales", "Menunggu Approval Sales Manager"),
+ ("waiting_approval_pimpinan", "Menunggu Approval Pimpinan / Kirim Surat"),
+ ("sent", "Approved & Sent")
+ ], default="draft", tracking=True)
+ send_date = fields.Datetime(string="Tanggal Kirim", tracking=True)
+ seven_days_after_sent_date = fields.Char(string="7 Hari Setelah Tanggal Kirim")
+ periode_invoices_terpilih = fields.Char(
+ string="Periode Invoices Terpilih",
+ compute="_compute_periode_invoices",
+ )
+
+ currency_id = fields.Many2one('res.currency')
+
+ # Grand total (total sisa semua line yang dicentang)
+ grand_total = fields.Monetary(
+ string='Total Sisa',
+ currency_field='currency_id',
+ compute='_compute_grand_total',
+ )
+
+ grand_total_text = fields.Char(
+ string="Total Terbilang",
+ compute="_compute_grand_total_text",
+ )
+
+ perihal_label = fields.Char(compute="_compute_perihal_label", string="Perihal Label")
+
+ payment_difficulty = fields.Selection(string="Payment Difficulty", related='partner_id.payment_difficulty', readonly=True)
+
+ sales_person_id = fields.Many2one('res.users', string='Salesperson', related='partner_id.user_id', readonly=True)
+
+ PERIHAL_SEQUENCE = {
+ "penagihan": "sp1",
+ "sp1": "sp2",
+ "sp2": "sp3",
+ }
+
+ @api.onchange('partner_id')
+ def _onchange_partner_id_domain(self):
+ unpaid_partner_ids = self.env['unpaid.invoice.view'].search([]).mapped('partner_id.id')
+ return {
+ 'domain': {
+ 'partner_id': [('id', 'in', unpaid_partner_ids)]
+ }
+ }
+ def _compute_perihal_label(self):
+ for rec in self:
+ rec.perihal_label = dict(self._fields['perihal'].selection).get(rec.perihal, '')
+
+ def action_create_next_letter(self):
+ for rec in self:
+ if rec.state != "sent":
+ raise UserError("Surat harus sudah terkirim sebelum bisa membuat surat lanjutan.")
+
+ next_perihal = self.PERIHAL_SEQUENCE.get(rec.perihal)
+ if not next_perihal:
+ raise UserError("Surat ini sudah pada tahap terakhir (SP3). Tidak bisa membuat lanjutan lagi.")
+
+ existing = self.search([
+ ('partner_id', '=', rec.partner_id.id),
+ ('perihal', '=', next_perihal),
+ ('state', '!=', 'draft') # optional: cek hanya yang sudah dikirim
+ ])
+ if existing:
+ raise UserError(f"Surat lanjutan {dict(self._fields['perihal'].selection).get(next_perihal)} "
+ f"untuk customer ini sudah dibuat: {', '.join(existing.mapped('name'))}")
+
+ # copy surat lama
+ new_vals = {
+ "tujuan_nama": rec.tujuan_nama,
+ "tujuan_email": rec.tujuan_email,
+ "perihal": next_perihal,
+ "partner_id": rec.partner_id.id,
+ "line_ids": [(0, 0, {
+ 'invoice_id': line.invoice_id.id,
+ 'invoice_number': line.invoice_number,
+ 'invoice_date': line.invoice_date,
+ 'invoice_date_due': line.invoice_date_due,
+ 'invoice_day_to_due': line.invoice_day_to_due,
+ 'new_invoice_day_to_due': line.new_invoice_day_to_due,
+ 'ref': line.ref,
+ 'amount_residual': line.amount_residual,
+ 'currency_id': line.currency_id.id,
+ 'payment_term_id': line.payment_term_id.id,
+ 'date_kirim_tukar_faktur': line.date_kirim_tukar_faktur,
+ 'date_terima_tukar_faktur': line.date_terima_tukar_faktur,
+ 'invoice_user_id': line.invoice_user_id.id,
+ 'sale_id': line.sale_id.id,
+ "selected": line.selected,
+ }) for line in rec.line_ids],
+ }
+ new_letter = self.create(new_vals)
+ self.env.user.notify_info(
+ message=f"{dict(self._fields['perihal'].selection).get(next_perihal)} berhasil dibuat ({new_letter.name}).",
+ title="Informasi",
+ sticky=False
+ )
+ new_letter.message_post(
+ body=
+ f"<b>{dict(self._fields['perihal'].selection).get(next_perihal)}</b> "
+ f"berhasil dibuat berdasarkan surat sebelumnya.<br/>"
+ f"Nomor Surat: <b>{new_letter.name}</b>"
+ )
+ rec.message_post(
+ body=(
+ f"Surat lanjutan dengan perihal <b>{dict(self._fields['perihal'].selection).get(next_perihal)}</b> "
+ f"telah dibuat sebagai kelanjutan dari surat ini.<br/>"
+ f"Nomor Surat Baru: <a href='/web#id={new_letter.id}&model=surat.piutang&view_type=form'><b>{new_letter.name}</b></a>"
+ )
+ )
+ return True
+
+
+ @api.depends("line_ids.selected", "line_ids.invoice_date")
+ def _compute_periode_invoices(self):
+ for rec in self:
+ selected_lines = rec.line_ids.filtered(lambda l: l.selected and l.invoice_date)
+ if not selected_lines:
+ rec.periode_invoices_terpilih = "-"
+ continue
+
+ dates = selected_lines.mapped("invoice_date")
+ min_date, max_date = min(dates), max(dates)
+
+ # Ambil bagian bulan & tahun
+ min_month = babel.dates.format_date(min_date, "MMMM", locale="id_ID")
+ min_year = min_date.year
+ max_month = babel.dates.format_date(max_date, "MMMM", locale="id_ID")
+ max_year = max_date.year
+
+ if min_year == max_year:
+ if min_month == max_month:
+ # example: Januari 2025
+ rec.periode_invoices_terpilih = f"{min_month} {min_year}"
+ else:
+ # example: Mei s/d Juni 2025
+ rec.periode_invoices_terpilih = f"{min_month} s/d {max_month} {max_year}"
+ else:
+ # example: Desember 2024 s/d Januari 2025
+ rec.periode_invoices_terpilih = f"{min_month} {min_year} s/d {max_month} {max_year}"
+
+ def _compute_grand_total_text(self):
+ tb = Terbilang()
+ for record in self:
+ res = ""
+ if record.grand_total and record.grand_total > 0:
+ try:
+ tb.parse(int(record.grand_total))
+ res = tb.getresult().title() + " Rupiah"
+ except Exception:
+ res = ""
+ record.grand_total_text = res
+
+ @api.depends('line_ids.amount_residual', 'line_ids.selected')
+ def _compute_grand_total(self):
+ for rec in self:
+ rec.grand_total = sum(
+ line.amount_residual or 0.0 for line in rec.line_ids if line.selected
+ )
+
+ @api.constrains("tujuan_email")
+ def _check_email_format(self):
+ for rec in self:
+ if rec.tujuan_email and not mail.single_email_re.match(rec.tujuan_email):
+ raise ValidationError(_("Format email tidak valid: %s") % rec.tujuan_email)
+
+ def action_approve(self):
+ wib = pytz.timezone('Asia/Jakarta')
+ now_wib = datetime.now(wib)
+
+ sales_manager_ids = [10] # ganti dengan ID user Sales Manager
+ pimpinan_user_ids = [7] # ganti dengan ID user Pimpinan
+
+ for rec in self:
+ # === SP1 s/d SP3 butuh dua tahap approval ===
+ if rec.perihal in ("sp1", "sp2", "sp3"):
+
+ # Tahap 1: Sales Manager approval
+ if rec.state == "waiting_approval_sales":
+ if self.env.user.id not in sales_manager_ids:
+ raise UserError("Hanya Sales Manager yang boleh menyetujui tahap ini.")
+ rec.state = "waiting_approval_pimpinan"
+ rec.message_post(body="Disetujui oleh Sales Manager. Menunggu Approval Pimpinan.")
+ continue
+
+ # Tahap 2: Pimpinan approval
+ if rec.state == "waiting_approval_pimpinan":
+ if self.env.user.id not in pimpinan_user_ids:
+ raise UserError("Hanya Pimpinan yang berhak menyetujui surat ini.")
+ 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 Piutang disetujui oleh Pimpinan dan berhasil dikirim.")
+ continue
+
+ # === Surat penagihan biasa (langsung Pimpinan approve) ===
+ if rec.perihal == "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.")
+
+ 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_send_letter(self):
+ self.ensure_one()
+
+ selected_lines = self.line_ids.filtered('selected')
+ if not selected_lines:
+ raise UserError(_("Tidak ada invoice yang dicentang untuk dikirim."))
+
+ 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>
+ </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')
+ pdf_content, _ = report._render_qweb_pdf([self.id])
+ attachment_base64 = base64.b64encode(pdf_content)
+
+ attachment = self.env['ir.attachment'].create({
+ 'name': f"{self.perihal_label} - {self.partner_id.name}.pdf",
+ 'type': 'binary',
+ 'datas': attachment_base64,
+ 'res_model': 'surat.piutang',
+ 'res_id': self.id,
+ 'mimetype': 'application/pdf',
+ })
+
+ values = {
+ # 'subject': template.subject.replace('${object.name}', self.name or ''),
+ 'subject': perihal_map.get(self.perihal, self.perihal or '') + " - " + (self.partner_id.name or ''),
+ 'email_to': self.tujuan_email,
+ 'email_from': 'finance@indoteknik.co.id',
+ 'body_html': body_html,
+ 'attachments': [(attachment.name, attachment.datas)],
+ 'reply_to': 'finance@indoteknik.co.id',
+ }
+
+ template.with_context(mail_post_autofollow=False).send_mail(
+ self.id,
+ force_send=True,
+ email_values=values
+ )
+
+ _logger.info(
+ f"Surat Piutang {self.name} terkirim ke {self.tujuan_email} "
+ f"({self.partner_id.name}), total {len(selected_lines)} invoice."
+ )
+
+ @api.onchange('partner_id')
+ def _onchange_partner_id(self):
+ if self.partner_id:
+ invoice_lines = self.env['unpaid.invoice.view'].search(
+ [('partner_id', '=', self.partner_id.id)],
+ order='new_invoice_day_to_due asc'
+ )
+ selected_invoice_id = self.env.context.get('default_selected_invoice_id')
+ lines = [(5, 0, 0)] # hapus semua line lama
+ lines += [(0, 0, {
+ 'invoice_id': inv.invoice_id.id,
+ 'invoice_number': inv.invoice_number,
+ 'invoice_date': inv.invoice_date,
+ 'invoice_date_due': inv.invoice_date_due,
+ 'invoice_day_to_due': inv.invoice_day_to_due,
+ 'new_invoice_day_to_due': inv.new_invoice_day_to_due,
+ 'ref': inv.ref,
+ 'amount_residual': inv.amount_residual,
+ 'currency_id': inv.currency_id.id,
+ 'payment_term_id': inv.payment_term_id.id,
+ 'date_kirim_tukar_faktur': inv.date_kirim_tukar_faktur,
+ 'date_terima_tukar_faktur': inv.date_terima_tukar_faktur,
+ 'invoice_user_id': inv.invoice_user_id.id,
+ 'sale_id': inv.sale_id.id,
+ 'selected': True if inv.invoice_id.id == selected_invoice_id else False,
+ }) for inv in invoice_lines]
+ self.line_ids = lines
+
+ def action_refresh_lines(self):
+ for rec in self:
+ if not rec.partner_id:
+ continue
+
+ # Ambil semua unpaid terbaru
+ invoice_views = self.env['unpaid.invoice.view'].search(
+ [('partner_id', '=', rec.partner_id.id)],
+ order='new_invoice_day_to_due asc'
+ )
+
+ existing_lines = {line.invoice_id.id: line for line in rec.line_ids}
+
+ # Cache selected status per invoice id
+ selected_map = {line.invoice_id.id: line.selected for line in rec.line_ids}
+
+ # Invoice id yang masih ada di unpaid
+ new_invoice_ids = invoice_views.mapped('invoice_id.id')
+
+ for inv in invoice_views:
+ if inv.invoice_id.id in existing_lines:
+ # update line lama
+ line = existing_lines[inv.invoice_id.id]
+ line.write({
+ # 'invoice_view_id': inv.id,
+ 'invoice_number': inv.invoice_number,
+ 'invoice_date': inv.invoice_date,
+ 'invoice_date_due': inv.invoice_date_due,
+ 'invoice_day_to_due': inv.invoice_day_to_due,
+ 'new_invoice_day_to_due': inv.new_invoice_day_to_due,
+ 'ref': inv.ref,
+ 'amount_residual': inv.amount_residual,
+ 'currency_id': inv.currency_id.id,
+ 'payment_term_id': inv.payment_term_id.id,
+ 'date_kirim_tukar_faktur': inv.date_kirim_tukar_faktur,
+ 'date_terima_tukar_faktur': inv.date_terima_tukar_faktur,
+ 'invoice_user_id': inv.invoice_user_id.id,
+ 'sale_id': inv.sale_id.id,
+ 'selected': selected_map.get(inv.invoice_id.id, line.selected),
+ })
+ else:
+ # preserve selected kalau pernah ada di cache
+ self.env['surat.piutang.line'].create({
+ 'surat_id': rec.id,
+ # 'invoice_view_id': inv.id,
+ 'invoice_id': inv.invoice_id.id,
+ 'invoice_number': inv.invoice_number,
+ 'invoice_date': inv.invoice_date,
+ 'invoice_date_due': inv.invoice_date_due,
+ 'invoice_day_to_due': inv.invoice_day_to_due,
+ 'new_invoice_day_to_due': inv.new_invoice_day_to_due,
+ 'ref': inv.ref,
+ 'amount_residual': inv.amount_residual,
+ 'currency_id': inv.currency_id.id,
+ 'payment_term_id': inv.payment_term_id.id,
+ 'date_kirim_tukar_faktur': inv.date_kirim_tukar_faktur,
+ 'date_terima_tukar_faktur': inv.date_terima_tukar_faktur,
+ 'invoice_user_id': inv.invoice_user_id.id,
+ 'sale_id': inv.sale_id.id,
+ 'selected': selected_map.get(inv.invoice_id.id, False),
+ })
+
+ # Hapus line yang tidak ada lagi di unpaid view
+ rec.line_ids.filtered(lambda l: l.invoice_id.id not in new_invoice_ids).unlink()
+
+ rec.message_post(
+ body=f"Line Invoices diperbarui. Total line saat ini: {len(rec.line_ids)}"
+ )
+
+ @api.model
+ def create(self, vals):
+ # Generate nomor surat otomatis
+ if not vals.get("name"):
+ seq = self.env["ir.sequence"].next_by_code("surat.piutang") or "000"
+ today = fields.Date.today()
+ 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":
+ vals["state"] = "waiting_approval_pimpinan"
+ else:
+ vals["state"] = "waiting_approval_sales"
+ return super().create(vals)
+
+class SuratPiutangLine(models.Model):
+ _name = 'surat.piutang.line'
+ _description = 'Surat Piutang Line'
+
+ surat_id = fields.Many2one('surat.piutang', string='Surat Piutang', ondelete='cascade')
+ # invoice_view_id = fields.Many2one('unpaid.invoice.view', string='Unpaid Invoice')
+ invoice_id = fields.Many2one('account.move', string='Invoice')
+ selected = fields.Boolean(string="Pilih", default=False)
+
+ invoice_number = fields.Char(string='Invoice Number')
+ invoice_date = fields.Date(string='Invoice Date')
+ invoice_date_due = fields.Date(string='Due Date')
+ invoice_day_to_due = fields.Integer(string='Day to Due')
+ new_invoice_day_to_due = fields.Integer(string='New Day to Due')
+ ref = fields.Char(string='Reference')
+ amount_residual = fields.Monetary(string='Amount Due Signed')
+ currency_id = fields.Many2one('res.currency')
+ payment_term_id = fields.Many2one('account.payment.term', string='Payment Terms')
+
+ date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur')
+ date_terima_tukar_faktur = fields.Date(string='Terima Faktur')
+ invoice_user_id = fields.Many2one('res.users', string='Salesperson')
+ sale_id = fields.Many2one('sale.order', string='Sale Order')
+
+ sort = fields.Integer(string='No Urut', compute='_compute_sort', store=False)
+
+ @api.depends('surat_id.line_ids.selected')
+ def _compute_sort(self):
+ for line in self:
+ if line.surat_id:
+ # Ambil semua line yang selected
+ selected_lines = line.surat_id.line_ids.filtered(lambda l: l.selected)
+ try:
+ line.sort = selected_lines.ids.index(line.id) + 1
+ except ValueError:
+ line.sort = 0
+ else:
+ line.sort = 0
diff --git a/indoteknik_custom/models/unpaid_invoice_view.py b/indoteknik_custom/models/unpaid_invoice_view.py
new file mode 100644
index 00000000..3eb6efc7
--- /dev/null
+++ b/indoteknik_custom/models/unpaid_invoice_view.py
@@ -0,0 +1,55 @@
+from odoo import models, fields
+
+class UnpaidInvoiceView(models.Model):
+ _name = 'unpaid.invoice.view'
+ _description = 'Unpaid Invoices Monitoring'
+ _auto = False
+ _rec_name = 'partner_name'
+ _order = 'partner_name, new_invoice_day_to_due DESC'
+
+ partner_id = fields.Many2one('res.partner', string='Partner')
+ partner_name = fields.Char(string='Partner Name')
+ # email = fields.Char()
+ # phone = fields.Char()
+ invoice_id = fields.Many2one('account.move', string='Invoice')
+ invoice_number = fields.Char(string='Invoice Number')
+ invoice_date = fields.Date()
+ invoice_date_due = fields.Date(string='Due Date')
+ date_terima_tukar_faktur = fields.Date(string='Terima Faktur')
+ currency_id = fields.Many2one('res.currency', string='Currency')
+ amount_total = fields.Monetary(string='Total Amount', currency_field='currency_id')
+ amount_residual = fields.Monetary(string='Sisa Amount', currency_field='currency_id')
+ payment_state = fields.Selection([
+ ('not_paid', 'Not Paid'),
+ ('in_payment', 'In Payment'),
+ ('paid', 'Paid'),
+ ('partial', 'Partially Paid'),
+ ('reversed', 'Reversed')], string='Payment State')
+ payment_term_id = fields.Many2one('account.payment.term', string='Payment Term')
+ invoice_day_to_due = fields.Integer(string="Day to Due")
+ new_invoice_day_to_due = fields.Integer(string="New Day Due")
+
+ ref = fields.Char(string='Reference')
+ invoice_user_id = fields.Many2one('res.users', string='Salesperson')
+ date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur')
+ sale_id = fields.Many2one('sale.order', string='Sale Order')
+
+ payment_difficulty = fields.Selection([
+ ('bermasalah', 'Bermasalah'),
+ ('sulit', 'Sulit'),
+ ('agak_sulit', 'Agak Sulit'),
+ ('normal', 'Normal'),
+ ], string="Payment Difficulty")
+
+ def action_create_surat_piutang(self):
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'surat.piutang',
+ 'view_mode': 'form',
+ 'target': 'current',
+ 'context': {
+ 'default_partner_id': self.partner_id.id,
+ 'default_selected_invoice_id': self.invoice_id.id,
+ }
+ }
diff --git a/indoteknik_custom/report/report_surat_piutang copy.xml b/indoteknik_custom/report/report_surat_piutang copy.xml
new file mode 100644
index 00000000..cb5762f3
--- /dev/null
+++ b/indoteknik_custom/report/report_surat_piutang copy.xml
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data>
+
+ <!-- External Layout tanpa company -->
+ <template id="external_layout_no_company">
+ <!-- HEADER -->
+ <div class="header">
+ <img t-att-src="'https://erp.indoteknik.com/api/image/ir.attachment/datas/2498521'"
+ class="img img-fluid w-100"/>
+ </div>
+
+ <!-- CONTENT -->
+ <div class="content mt-5 mb-5 ml-3 mr-3">
+ <t t-raw="0"/>
+ </div>
+
+ <!-- FOOTER -->
+ <div class="footer">
+ <img t-att-src="'https://erp.indoteknik.com/api/image/ir.attachment/datas/2498529'"
+ style="height:60px;"/>
+ </div>
+ </template>
+
+ <!-- Report Action -->
+ <record id="action_report_surat_piutang" model="ir.actions.report">
+ <field name="name">Surat Peringatan Piutang</field>
+ <field name="model">surat.piutang</field>
+ <field name="report_type">qweb-pdf</field>
+ <field name="report_name">indoteknik_custom.report_surat_piutang_formal_custom</field>
+ <field name="report_file">indoteknik_custom.report_surat_piutang_formal_custom</field>
+ <field name="binding_model_id" ref="model_surat_piutang"/>
+ <field name="binding_type">report</field>
+ </record>
+
+ <!-- QWeb Template Surat -->
+ <template id="report_surat_piutang_formal_custom">
+ <t t-call="indoteknik_custom.external_layout_no_company">
+ <t t-set="doc" t-value="docs[0] if docs else None"/>
+
+ <!-- SURAT CONTENT -->
+ <main class="o_report_layout_standard" style="font-size:12pt; font-family: Arial, sans-serif;">
+
+ <!-- Header Surat -->
+ <div class="row mb-3">
+ <div class="col-6">
+ Ref. No: <t t-esc="doc.name or '-'"/>
+ </div>
+ <div class="col-6 text-right">
+ Jakarta, <t t-esc="doc.send_date and doc.send_date.strftime('%d %B %Y') or '-'"/>
+ </div>
+ </div>
+
+ <!-- Tujuan -->
+ <div class="mb-3">
+ <strong>Kepada Yth.</strong><br/>
+ <t t-esc="doc.partner_id.name if doc and doc.partner_id else '-'"/><br/>
+ <t t-esc="doc.partner_id.street if doc and doc.partner_id else '-'"/><br/>
+ <t t-esc="doc.partner_id.country_id.name if doc and doc.partner_id and doc.partner_id.country_id else '-'"/>
+ </div>
+
+ <!-- UP & Perihal -->
+ <div class="mb-4">
+ U.P. : <t t-esc="doc.tujuan_nama or '-'"/><br/>
+ <strong>Perihal:</strong> <t t-esc="doc.perihal or '-'"/>
+ </div>
+
+ <!-- Isi Surat -->
+ <div class="mb-3">Dengan Hormat,</div>
+ <div class="mb-3">Yang bertanda tangan di bawah ini menyampaikan sebagai berikut:</div>
+
+ <div class="mb-3 text-justify">
+ Namun, bersama surat ini kami ingin mengingatkan bahwa hingga tanggal surat ini dibuat, masih terdapat tagihan yang belum diselesaikan oleh pihak
+ <t t-esc="doc.partner_id.name if doc and doc.partner_id else '-'"/> periode bulan <t t-esc="doc.periode_invoices_terpilih or '-'"/>, berdasarkan data korespondensi dan laporan keuangan yang kami kelola,
+ <t t-esc="doc.partner_id.name if doc and doc.partner_id else '-'"/> (“Saudara”) masih mempunyai tagihan yang telah jatuh tempo dan belum dibayarkan sejumlah
+ <t t-esc="doc.grand_total_text or '-'"/> (“Tagihan”).
+ </div>
+
+ <div class="mb-3">Berikut kami lampirkan Rincian Tagihan yang telah Jatuh Tempo:</div>
+
+ <!-- Tabel Invoice -->
+ <table class="table table-sm table-bordered mb-4">
+ <thead class="thead-light">
+ <tr>
+ <th>Invoice Number</th>
+ <th>Invoice Date</th>
+ <th>Due Date</th>
+ <th class="text-center">Day to Due</th>
+ <th>Reference</th>
+ <th class="text-right">Amount Due</th>
+ <th>Payment Terms</th>
+ </tr>
+ </thead>
+ <tbody>
+ <t t-foreach="doc.line_ids.filtered(lambda l: l.selected)" t-as="line">
+ <tr>
+ <td><t t-esc="line.invoice_number or '-'"/></td>
+ <td><t t-esc="line.invoice_date and line.invoice_date.strftime('%d-%m-%Y') or '-'"/></td>
+ <td><t t-esc="line.invoice_date_due and line.invoice_date_due.strftime('%d-%m-%Y') or '-'"/></td>
+ <td class="text-center"><t t-esc="line.new_invoice_day_to_due or '-'"/></td>
+ <td><t t-esc="line.ref or '-'"/></td>
+ <td class="text-right"><t t-esc="line.amount_residual or '-'"/></td>
+ <td><t t-esc="line.payment_term_id.name or '-'"/></td>
+ </tr>
+ </t>
+ </tbody>
+ <tfoot>
+ <tr class="font-weight-bold">
+ <td colspan="6" class="text-right">
+ GRAND TOTAL INVOICE YANG BELUM DIBAYAR DAN TELAH JATUH TEMPO
+ </td>
+ <td class="text-right">
+ <t t-esc="doc.grand_total or '-'"/> (<t t-esc="doc.grand_total_text or '-'"/>)
+ </td>
+ </tr>
+ </tfoot>
+ </table>
+
+ <!-- Isi Penutup -->
+ <div class="mb-3">
+ Kami belum menerima konfirmasi pelunasan ataupun pembayaran sebagian dari total kewajiban tersebut. Kami sangat terbuka untuk berdiskusi serta mencari solusi terbaik agar kerja sama tetap berjalan baik.
+ </div>
+
+ <div class="mb-3">
+ Oleh karena itu, kami mohon perhatian dan itikad baik dari pihak <t t-esc="doc.partner_id.name if doc and doc.partner_id else '-'"/> untuk segera melakukan pelunasan atau memberikan informasi terkait rencana pembayaran paling lambat dalam waktu 7 (tujuh) hari kerja sejak surat ini diterima.
+ </div>
+
+ <div class="mb-3">
+ Jika dalam waktu yang telah ditentukan belum ada penyelesaian atau tanggapan, kami akan mempertimbangkan untuk melanjutkan proses sesuai ketentuan yang berlaku.
+ </div>
+
+ <div class="mb-4">
+ Demikian kami sampaikan. Atas perhatian dan kerja samanya, kami ucapkan terima kasih.
+ </div>
+
+ <div class="mb-2">Hormat kami,</div>
+
+ <!-- TTD -->
+ <div class="mt-5">
+ <img t-att-src="'https://erp.indoteknik.com/api/image/ir.attachment/datas/2851919'" style="width:200px; height:auto;"/><br/>
+ <div>Nama: Akbar Prabawa<br/>Jabatan: General Manager</div>
+ </div>
+
+ </main>
+ </t>
+ </template>
+
+ </data>
+</odoo>
diff --git a/indoteknik_custom/report/report_surat_piutang.xml b/indoteknik_custom/report/report_surat_piutang.xml
new file mode 100644
index 00000000..770aa535
--- /dev/null
+++ b/indoteknik_custom/report/report_surat_piutang.xml
@@ -0,0 +1,241 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data>
+
+ <!-- Report Action -->
+ <record id="action_report_surat_piutang" model="ir.actions.report">
+ <field name="name">Surat Peringatan Piutang</field>
+ <field name="model">surat.piutang</field>
+ <field name="report_type">qweb-pdf</field>
+ <field name="report_name">indoteknik_custom.report_surat_piutang</field>
+ <field name="report_file">indoteknik_custom.report_surat_piutang</field>
+ <field name="print_report_name">'%s - %s' % (object.perihal_label or '', object.partner_id.name or '')</field>
+ <field name="binding_model_id" ref="model_surat_piutang"/>
+ <field name="binding_type">report</field>
+ </record>
+
+ <template id="external_layout_surat_piutang">
+ <t t-call="web.html_container">
+
+ <!-- Header -->
+ <div class="header">
+ <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2498521"
+ style="width:100%; display: block;"/>
+ </div>
+
+ <!-- Body -->
+ <div class="article" style="margin: 0 1.5cm 0 1.5cm; ">
+ <t t-raw="0"/>
+ </div>
+
+ <!-- Footer -->
+ <div class="footer">
+ <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2859765"
+ style="width:100%; display: block;"/>
+ </div>
+ </t>
+ </template>
+
+
+
+ <!-- Wrapper Template -->
+ <template id="report_surat_piutang">
+ <t t-call="web.html_container">
+ <t t-foreach="docs" t-as="doc">
+ <t t-call="indoteknik_custom.report_surat_piutang_document"
+ t-lang="doc.partner_id.lang"/>
+ </t>
+ </t>
+ </template>
+
+ <!-- Document Template -->
+ <template id="report_surat_piutang_document">
+ <t t-call="indoteknik_custom.external_layout_surat_piutang">
+ <t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)"/>
+ <div class="page">
+
+ <!-- Ref & Date -->
+ <div class="row mb3">
+ <div class="col-6">
+ Ref. No: <t t-esc="doc.name or '-'"/>
+ </div>
+ <div class="col-6 text-right">
+ Jakarta, <t t-esc="doc.send_date and doc.send_date.strftime('%d %B %Y') or '-'"/>
+ </div>
+ </div>
+ <br/>
+ <!-- Tujuan -->
+ <div class="mb3" style="max-width:500px; word-wrap:break-word; white-space:normal;">
+ <strong>Kepada Yth.</strong><br/>
+ <strong><t t-esc="doc.partner_id.name or '-'"/></strong><br/>
+ <span style="display:inline-block; max-width:400px; word-wrap:break-word; white-space:normal;">
+ <t t-esc="doc.partner_id.street or ''"/>
+ </span><br/>
+ <u>Republik Indonesia</u>
+ </div>
+ <br/>
+
+ <!-- UP & Perihal -->
+ <table style="margin-left:2cm;">
+ <tr style="font-weight: bold;">
+ <td style="padding-right:10px;">U.P.</td>
+ <td>: <t t-esc="doc.tujuan_nama or '-'"/></td>
+ </tr>
+ <tr style="font-weight: bold;">
+ <td style="padding-right:10px;">Perihal</td>
+ <td>: <u><t t-esc="doc.perihal_label or '-'"/></u></td>
+ </tr>
+ </table>
+
+ <br/>
+
+ <!-- Isi Surat -->
+ <p><strong>Dengan Hormat,</strong></p>
+ <p>Yang bertanda tangan di bawah ini:</p>
+
+ <p class="text-justify">
+ <strong>PT. Indoteknik Dotcom Gemilang</strong>, suatu perseroan terbatas yang didirikan berdasarkan hukum Negara Republik
+ Indonesia, yang beralamat di Jalan Bandengan Utara 85A No. 8-9, RT.003/RW.016, Penjaringan, Penjaringan, Jakarta
+ Utara, DKI Jakarta 14440, Republik Indonesia, dalam hal ini diwakili secara sah oleh Akbar Prabawa selaku General
+ Manager, dengan ini menyampaikan sebagai berikut:
+ </p>
+
+ <p class="text-justify">
+ Kami mengucapkan terima kasih atas kerja sama yang telah terjalin dengan baik selama ini antara perusahaan kami
+ dengan <strong><t t-esc="doc.partner_id.name or '-'"/></strong>.
+ </p>
+
+ <p class="text-justify">
+ Namun, bersama surat ini kami ingin mengingatkan bahwa hingga tanggal surat ini dibuat, masih terdapat tagihan yang
+ belum diselesaikan oleh pihak <strong><t t-esc="doc.partner_id.name or '-'"/></strong> kepada kami periode bulan
+ <t t-esc="doc.periode_invoices_terpilih or '-'"/>, bahwa berdasarkan data korespondensi dan laporan keuangan yang kami kelola,
+ <t t-esc="doc.partner_id.name or '-'"/> <b>(“Saudara”)</b> masih mempunyai tagihan yang telah jatuh tempo dan belum dibayarkan sejumlah
+ <t t-esc="doc.grand_total_text or '-'"/> <b>(“Tagihan”)</b>.
+ </p>
+
+ <p>Berikut kami lampirkan Rincian Tagihan yang telah Jatuh Tempo:</p>
+
+ <!-- Tabel Invoice -->
+ <table class="table table-sm o_main_table"
+ style="font-size:13px; border:1px solid #000; border-collapse: collapse; width:100%; table-layout: fixed;">
+
+ <thead style="background:#f5f5f5;">
+ <tr>
+ <th style="border:1px solid #000; padding:4px; width:5%; font-weight: bold;" class="text-center">No.</th>
+ <th style="border:1px solid #000; padding:4px; width:15%; font-weight: bold;">Invoice Number</th>
+ <th style="border:1px solid #000; padding:4px; width:10%; font-weight: bold;">Invoice Date</th>
+ <th style="border:1px solid #000; padding:4px; width:10%; font-weight: bold;">Due Date</th>
+ <th style="border:1px solid #000; padding:4px; width:6%; font-weight: bold;" class="text-center">Day to Due</th>
+ <th style="border:1px solid #000; padding:4px; width:16%; font-weight: bold;">Reference</th>
+ <th style="border:1px solid #000; padding:4px; width:17%; font-weight: bold;" class="text-right">Amount Due</th>
+ <th style="border:1px solid #000; padding:4px; width:12%; font-weight: bold;">Payment Terms</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <tr t-foreach="doc.line_ids.filtered(lambda l: l.selected)" t-as="line">
+
+ <!-- Nomor Urut -->
+ <td style="border:1px solid #000; padding:4px; text-align:center;">
+ <t t-esc="line.sort or '-'"/>
+ </td>
+
+ <!-- Invoice Number -->
+ <td style="border:1px solid #000; padding:4px; word-wrap: break-word;">
+ <t t-esc="line.invoice_number or '-'"/>
+ </td>
+
+ <!-- Invoice Date -->
+ <td style="border:1px solid #000; padding:4px;">
+ <t t-esc="line.invoice_date and line.invoice_date.strftime('%d-%m-%Y') or '-'"/>
+ </td>
+
+ <!-- Due Date -->
+ <td style="border:1px solid #000; padding:4px;">
+ <t t-esc="line.invoice_date_due and line.invoice_date_due.strftime('%d-%m-%Y') or '-'"/>
+ </td>
+
+ <!-- Day to Due -->
+ <td style="border:1px solid #000; padding:4px; text-align:center;">
+ <t t-esc="line.new_invoice_day_to_due or '-'"/>
+ </td>
+
+ <!-- Reference -->
+ <td style="border:1px solid #000; padding:4px; word-wrap: break-word;">
+ <t t-esc="line.ref or '-'"/>
+ </td>
+
+ <!-- Amount Due -->
+ <td style="border:1px solid #000; padding:4px; text-align:right;">
+ Rp. <t t-esc="'{:,.0f}'.format(line.amount_residual).replace(',', '.')"/>
+ </td>
+
+ <!-- Payment Terms -->
+ <td style="border:1px solid #000; padding:4px; word-wrap: break-word;">
+ <t t-esc="line.payment_term_id.name or '-'"/>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="5" class="text-left" style="border:1px solid #000; padding:4px; word-wrap: break-word; white-space: normal; font-weight: bold;">
+ GRAND TOTAL INVOICE YANG BELUM DIBAYAR DAN TELAH JATUH TEMPO
+ </td>
+ <td colspan="3" class="text-right" style="border:1px solid #000; padding:4px; word-wrap: break-word; white-space: normal; font-weight: bold;">
+ Rp. <t t-esc="'{:,.0f}'.format(doc.grand_total).replace(',', '.')"/>
+ (<t t-esc="doc.grand_total_text or '-'"/>)
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+
+ <!-- Penutup -->
+ <p class="text-justify">
+ Kami belum menerima konfirmasi pelunasan ataupun pembayaran sebagian dari total kewajiban tersebut dan kami
+ memahami bahwa setiap perusahaan bisa saja menghadapi kendala operasional maupun keuangan, dan kami sangat
+ terbuka untuk berdiskusi serta mencari solusi terbaik bersama agar kerja sama kita tetap berjalan baik ke depannya.
+ </p>
+
+ <p class="text-justify">
+ Oleh karena itu, kami mohon perhatian dan itikad baik dari pihak <strong><t t-esc="doc.partner_id.name or '-'"/></strong>
+ untuk segera melakukan pelunasan atau memberikan informasi terkait rencana pembayaran paling lambat dalam waktu 7 (tujuh) hari kerja sejak surat ini diterima.
+ </p>
+
+ <p class="text-justify">
+ Jika dalam waktu yang telah ditentukan belum ada penyelesaian atau tanggapan, kami akan mempertimbangkan untuk
+ melanjutkan proses sesuai ketentuan yang berlaku.
+ </p>
+
+ <p class="text-justify">
+ Demikian kami sampaikan. Atas perhatian dan kerja samanya, kami ucapkan terima kasih.
+ </p>
+ <div class="mt32">
+ <p>Hormat kami,<br/>
+ <strong>PT. Indoteknik Dotcom Gemilang</strong>
+ </p>
+
+ <div style="height:120px; position: relative;">
+ <t t-if="doc.perihal != 'penagihan'">
+ <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2851919"
+ style="width:300px; height:auto; margin-top:-40px;"/>
+ </t>
+ <t t-else="">
+ <div style="height:100px;"></div>
+ </t>
+ </div>
+ <table style="margin-top:10px;">
+ <tr style="border-top:1px solid #000; font-weight: bold;">
+ <td style="padding-right:50px; white-space: nowrap;">Nama</td>
+ <td>: Akbar Prabawa</td>
+ </tr>
+ <tr style="font-weight: bold;">
+ <td style="padding-right:50px; white-space: nowrap;">Jabatan</td>
+ <td>: General Manager</td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ </t>
+ </template>
+
+ </data>
+</odoo>
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 3325e894..ea6670eb 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -198,4 +198,7 @@ access_tukar_guling_mapping_koli_all_users,tukar.guling.mapping.koli.all.users,m
access_sync_promise_date_wizard,access.sync.promise.date.wizard,model_sync_promise_date_wizard,base.group_user,1,1,1,1
access_sync_promise_date_wizard_line,access.sync.promise.date.wizard.line,model_sync_promise_date_wizard_line,base.group_user,1,1,1,1
access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1
-access_sj_tele,access.sj.tele,model_sj_tele,base.group_system,1,1,1,1 \ No newline at end of file
+access_unpaid_invoice_view,access.unpaid.invoice.view,model_unpaid_invoice_view,base.group_user,1,1,1,1
+access_surat_piutang_user,surat.piutang user,model_surat_piutang,base.group_user,1,1,1,1
+access_surat_piutang_line_user,surat.piutang.line user,model_surat_piutang_line,base.group_user,1,1,1,1
+access_sj_tele,access.sj.tele,model_sj_tele,base.group_system,1,1,1,1
diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml
index 94c2cd07..4b8fec53 100644
--- a/indoteknik_custom/views/ir_sequence.xml
+++ b/indoteknik_custom/views/ir_sequence.xml
@@ -228,5 +228,14 @@
<field name="number_increment">1</field>
<field name="active">True</field>
</record>
+
+ <record id="seq_surat_piutang" model="ir.sequence">
+ <field name="name">Surat Piutang</field>
+ <field name="code">surat.piutang</field>
+ <field name="prefix"></field> <!-- format manual di model -->
+ <field name="padding">3</field>
+ <field name="number_next">1</field>
+ <field name="number_increment">1</field>
+ </record>
</data>
</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/letter_receivable.xml b/indoteknik_custom/views/letter_receivable.xml
new file mode 100644
index 00000000..98ea7768
--- /dev/null
+++ b/indoteknik_custom/views/letter_receivable.xml
@@ -0,0 +1,190 @@
+<odoo>
+ <!-- Tree View -->
+ <record id="view_surat_piutang_tree" model="ir.ui.view">
+ <field name="name">surat.piutang.tree</field>
+ <field name="model">surat.piutang</field>
+ <field name="arch" type="xml">
+ <tree string="Surat Piutang">
+ <field name="name"/>
+ <field name="partner_id"/>
+ <field name="perihal"/>
+ <field name="state" widget="badge"
+ decoration-danger="state == 'draft'"
+ decoration-warning="state in ('waiting_approval_sales', 'waiting_approval_pimpinan')"
+ decoration-success="state == 'sent'"/>
+ <field name="send_date"/>
+ <!-- <field name="line_ids" widget="one2many_list"/> -->
+ </tree>
+ </field>
+ </record>
+
+ <!-- Form View -->
+ <record id="view_surat_piutang_form" model="ir.ui.view">
+ <field name="name">surat.piutang.form</field>
+ <field name="model">surat.piutang</field>
+ <field name="arch" type="xml">
+ <form string="Surat Piutang">
+ <header>
+ <field name="state" widget="statusbar" statusbar_visible="draft,waiting_approval_sales,waiting_approval_pimpinan,sent"/>
+ <button name="action_approve"
+ type="object"
+ string="Approve"
+ class="btn-primary"
+ attrs="{'invisible':[('state', '=', 'sent')]}"/>
+ <button name="action_create_next_letter"
+ string="Buat Surat Lanjutan"
+ type="object"
+ class="btn-primary"
+ attrs="{'invisible': ['|', ('state', '!=', 'sent'), ('perihal', '=', 'sp3')]}"/>
+ <!-- <button name="action_send_letter" type="object" string="Email Send" class="btn-primary"/> -->
+ </header>
+ <div class="alert alert-info"
+ role="alert"
+ style="height: 40px; margin-bottom:0px;"
+ attrs="{'invisible':[('state', '!=', 'draft')]}">
+ Selamat Datang di form Pengajuan Surat Piutang, Pastikan data sudah benar sebelum mengajukan approval.
+ </div>
+ <div class="alert alert-info"
+ role="alert"
+ style="height: 40px; margin-bottom:0px;"
+ attrs="{'invisible': ['|', ('perihal', '!=', 'penagihan'), ('state', '!=', 'waiting_approval_pimpinan')]}">
+ <strong>Info!</strong> Surat resmi penagihan telah diajukan &amp; surat otomatis terkirim bila telah di approve.
+ </div>
+ <div class="alert alert-info"
+ role="alert"
+ style="height: 40px; margin-bottom:0px;"
+ attrs="{'invisible':[('state', '!=', 'waiting_approval_sales')]}">
+ <strong>Info!</strong> Surat peringatan piutang ini sedang menunggu persetujuan dari <b>Sales Manager</b>.
+ Silakan hubungi Sales Manager terkait untuk melakukan approval agar proses dapat dilanjutkan ke tahap berikutnya.
+ </div>
+ <div class="alert alert-info"
+ role="alert"
+ style="margin-bottom:0px;"
+ attrs="{'invisible': ['|', ('perihal', '=', 'penagihan'), ('state', '!=', 'waiting_approval_pimpinan')]}">
+ <strong>Info!</strong> Surat peringatan piutang ini sedang menunggu persetujuan dari <b>Pimpinan</b>.
+ Silakan hubungi Pimpinan terkait untuk melakukan approval agar surat dapat terkirim otomatis ke customer.
+ </div>
+ <div class="alert alert-success"
+ role="alert"
+ style="height: 40px; margin-bottom:0px;"
+ attrs="{'invisible': ['|', ('perihal', '!=', 'sp3'), ('state', 'not in', ['draft', 'sent'])]}">
+ Surat Piutang berhasil terkirim dan silahkan klik tombol 'Buat Surat Lanjutan' untuk membuat surat piutang lanjutan.
+ </div>
+ <sheet>
+ <div class="oe_title">
+ <h1>
+ <field name="name" readonly="1"/>
+ </h1>
+ </div>
+ <group colspan="2">
+ <group>
+ <field name="tujuan_nama" attrs="{'readonly':[('state','=','sent')]}"/>
+ <field name="tujuan_email" attrs="{'readonly':[('state','=','sent')]}"/>
+ <field name="perihal" attrs="{'readonly':[('state','=','sent')]}"/>
+ <field name="partner_id" options="{'no_create': True}" attrs="{'readonly':[('state','=','sent')]}"/>
+ </group>
+ <group>
+ <field name="payment_difficulty"/>
+ <field name="sales_person_id"/>
+ <field name="send_date" readonly="1"/>
+ </group>
+ </group>
+ <!-- <group>
+ <button name="action_refresh_lines"
+ string="Refresh Invoices"
+ type="object"
+ class="btn-primary"
+ help="Refresh Invoices agar data tetap update"/>
+ </group> -->
+ <notebook>
+ <page string="Invoice Lines">
+ <div class="alert alert-info"
+ role="alert"
+ style="height: 40px; margin-bottom:0px;">
+ <strong>Info!</strong> Hanya invoice yang dipilih (tercentang) akan disertakan dalam dokumen surat piutang.
+ </div>
+ <!-- Flex container -->
+ <div style="display:flex; justify-content:space-between; align-items:center;">
+ <div>
+ <div>
+ <strong>Grand Total Invoice Terpilih:<br/>Rp.
+ <field name="grand_total"/> (
+ <field name="grand_total_text"/>
+ )
+ </strong>
+ </div>
+ <div>
+ <strong>Periode Invoices Terpilih:
+ <field name="periode_invoices_terpilih"/>
+ </strong>
+ </div>
+ </div>
+ <div>
+ <button name="action_refresh_lines"
+ string="Refresh Invoices"
+ type="object"
+ class="btn-primary"
+ style="margin-left:10px;"
+ help="Refresh Invoices agar data tetap update"/>
+ </div>
+ </div>
+ <field name="line_ids" attrs="{'readonly': [('state', '=', 'sent')]}">
+ <tree editable="bottom" create="false" delete="false">
+ <field name="selected"/>
+ <field name="invoice_id" readonly="1" optional="hide" force_save="1"/>
+ <field name="invoice_number" readonly="1" force_save="1"/>
+ <field name="ref" readonly="1" force_save="1"/>
+ <field name="invoice_date" readonly="1" force_save="1"/>
+ <field name="invoice_date_due" readonly="1" force_save="1"/>
+ <field name="invoice_day_to_due" readonly="1" force_save="1"/>
+ <field name="new_invoice_day_to_due" readonly="1" force_save="1"/>
+ <field name="amount_residual" readonly="1" force_save="1" sum="Grand Total"/>
+ <field name="currency_id" readonly="1" optional="hide" force_save="1"/>
+ <field name="payment_term_id" readonly="1" force_save="1"/>
+ <field name="date_kirim_tukar_faktur" readonly="1" optional="hide" force_save="1"/>
+ <field name="date_terima_tukar_faktur" readonly="1" optional="hide" force_save="1"/>
+ <field name="invoice_user_id" readonly="1" optional="hide" force_save="1"/>
+ <field name="sale_id" readonly="1" optional="hide" force_save="1"/>
+ </tree>
+ </field>
+ </page>
+ </notebook>
+ <div style="font-size:13px; color:#444; line-height:1.5;">
+ Surat piutang akan diterbitkan berdasarkan lama keterlambatan pembayaran.<br/>
+ Pilih invoice yang sesuai dengan kriteria berikut:
+ <ul style="margin:4px 0 0 18px;">
+ <li>Keterlambatan ≥ 45 hari → <em>Surat Resmi Penagihan (tanpa ttd digital &amp; cap stempel pimpinan)</em></li>
+ <li>Keterlambatan ≥ 60 hari → <em>Surat Peringatan Piutang ke-1 </em></li>
+ <li>Keterlambatan ≥ 70 hari → <em>Surat Peringatan Piutang ke-2 </em></li>
+ <li>Keterlambatan ≥ 80 hari → <em>Surat Peringatan Piutang ke-3 </em></li>
+ </ul>
+ </div>
+ </sheet>
+ <div class="oe_chatter">
+ <field name="message_follower_ids" widget="mail_followers"/>
+ <field name="message_ids" widget="mail_thread"/>
+ </div>
+ </form>
+ </field>
+ </record>
+
+ <!-- Menu -->
+ <record id="menu_surat_piutang_root" model="ir.ui.menu">
+ <field name="name">Surat Piutang</field>
+ <field name="parent_id" ref="account.menu_finance"/>
+ <field name="sequence" eval="10"/>
+ </record>
+
+ <record id="action_surat_piutang" model="ir.actions.act_window">
+ <field name="name">Surat Piutang</field>
+ <field name="res_model">surat.piutang</field>
+ <field name="view_mode">tree,form</field>
+ <field name="view_id" ref="view_surat_piutang_tree"/>
+ </record>
+
+ <menuitem id="menu_surat_piutang"
+ name="Surat Piutang"
+ parent="account.menu_finance_receivables"
+ action="action_surat_piutang"
+ sequence="1"/>
+</odoo>
diff --git a/indoteknik_custom/views/letter_receivable_mail_template.xml b/indoteknik_custom/views/letter_receivable_mail_template.xml
new file mode 100644
index 00000000..fa0fbc86
--- /dev/null
+++ b/indoteknik_custom/views/letter_receivable_mail_template.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <data noupdate="0">
+ <record id="letter_receivable_mail_template" model="mail.template">
+ <field name="name">Surat Piutang Invoices</field>
+ <field name="model_id" ref="indoteknik_custom.model_surat_piutang"/>
+ <field name="subject"></field>
+ <field name="email_from">finance@indoteknik.co.id</field>
+ <field name="email_to"></field>
+ <field name="body_html" type="html">
+ <div style="font-family:Arial, sans-serif; font-size:13px; color:#333;">
+ <div><b>Dengan hormat,</b></div>
+ <br/>
+ <div>Kepada Yth.</div>
+ <div><b>Manajemen ${object.partner_id.name}</b></div>
+ <br/>
+ <div>
+ Melalui email ini, kami ingin mengingatkan kembali terkait kewajiban pembayaran
+ ${object.partner_id.name} atas transaksi dengan rincian sebagai berikut:
+ </div>
+ <br/>
+
+ <table cellpadding="6" cellspacing="0" width="100%"
+ style="border-collapse:collapse; font-size:12px; border:1px solid #ddd;">
+ <thead>
+ <tr style="background-color:#f2f2f2; text-align:left;">
+ <th style="border:1px solid #ddd;">Invoice Number</th>
+ <th style="border:1px solid #ddd;">Customer</th>
+ <th style="border:1px solid #ddd;">Invoice Date</th>
+ <th style="border:1px solid #ddd;">Due Date</th>
+ <th style="border:1px solid #ddd;">Days To Due</th>
+ <th style="border:1px solid #ddd;">Reference</th>
+ <th style="border:1px solid #ddd;">Amount Due Signed</th>
+ <th style="border:1px solid #ddd;">Payment Terms</th>
+ </tr>
+ </thead>
+ <tbody>
+ <!-- baris invoice akan diinject dari Python -->
+ </tbody>
+ </table>
+
+ <p>
+ Hingga saat ini, kami belum menerima pembayaran atas tagihan tersebut.
+ Mohon konfirmasi dan tindak lanjut dari pihak saudara paling lambat pada
+ tanggal <b>${object.seven_days_after_sent_date}</b> (7 hari setelah email ini dikirimkan).
+ </p>
+
+ <p>
+ Sebagai informasi, kami lampirkan <b>${object.perihal}</b> untuk menjadi perhatian.
+ Jika tidak ada tanggapan atau penyelesaian dalam batas waktu tersebut, kami akan
+ melanjutkan dengan pengiriman surat peringatan berikutnya dan mengambil langkah-langkah
+ penyelesaian sesuai ketentuan yang berlaku.
+ </p>
+
+ <p>
+ Demikian kami sampaikan. Atas perhatian dan kerja samanya, kami ucapkan terima kasih.
+ </p>
+
+ <br/><br/>
+ <p>
+ <b>
+ Best Regards,<br/><br/>
+ Widya R.<br/>
+ Dept. Finance<br/>
+ PT. INDOTEKNIK DOTCOM GEMILANG<br/>
+ <img src="https://erp.indoteknik.com/api/image/ir.attachment/datas/2135765"
+ alt="Indoteknik" style="max-width:18%; height:auto;"/><br/>
+ <a href="https://wa.me/6285716970374" target="_blank">+62-857-1697-0374</a> |
+ <a href="mailto:finance@indoteknik.co.id">finance@indoteknik.co.id</a>
+ </b>
+ </p>
+ </div>
+ </field>
+ <field name="auto_delete" eval="True"/>
+ </record>
+ </data>
+</odoo>
diff --git a/indoteknik_custom/views/unpaid_invoice_view.xml b/indoteknik_custom/views/unpaid_invoice_view.xml
new file mode 100644
index 00000000..e56bbee7
--- /dev/null
+++ b/indoteknik_custom/views/unpaid_invoice_view.xml
@@ -0,0 +1,96 @@
+<odoo>
+ <!-- Tree view -->
+ <record id="view_unpaid_invoice_tree" model="ir.ui.view">
+ <field name="name">unpaid.invoice.view.tree</field>
+ <field name="model">unpaid.invoice.view</field>
+ <field name="arch" type="xml">
+ <tree string="Unpaid Invoices Monitoring" create="false" delete="false" edit="false">
+ <field name="partner_id"/>
+ <field name="invoice_number"/>
+ <field name="ref"/>
+ <field name="invoice_date"/>
+ <field name="date_kirim_tukar_faktur"/>
+ <field name="date_terima_tukar_faktur"/>
+ <field name="payment_term_id"/>
+ <field name="invoice_date_due" widget="badge" decoration-danger="invoice_day_to_due &lt; 0"/>
+ <field name="invoice_day_to_due" readonly="1"/>
+ <field name="new_invoice_day_to_due" readonly="1"/>
+ <field name="amount_total"/>
+ <field name="amount_residual"/>
+ <field name="payment_state" widget="badge"
+ decoration-danger="payment_state == 'not_paid'"
+ decoration-warning="payment_state == 'partial'"/>
+ <field name="invoice_user_id"/>
+ <field name="payment_difficulty" widget="badge"
+ decoration-info="payment_difficulty == 'normal'"
+ decoration-warning="payment_difficulty in ('agak_sulit', 'sulit')"
+ decoration-danger="payment_difficulty == 'bermasalah'"/>
+ </tree>
+ </field>
+ </record>
+
+ <!-- Form view -->
+ <record id="view_unpaid_invoice_form" model="ir.ui.view">
+ <field name="name">unpaid.invoice.view.form</field>
+ <field name="model">unpaid.invoice.view</field>
+ <field name="arch" type="xml">
+ <form string="Unpaid Invoice Detail" create="false" edit="false" delete="false">
+ <sheet>
+ <group>
+ <group>
+ <field name="partner_id"/>
+ <field name="invoice_id"/>
+ <field name="ref"/>
+ <field name="invoice_date"/>
+ <field name="invoice_date_due" widget="badge" decoration-danger="invoice_day_to_due &lt; 0"/>
+ <field name="date_kirim_tukar_faktur"/>
+ <field name="date_terima_tukar_faktur"/>
+ <field name="payment_term_id"/>
+ </group>
+ <group>
+ <field name="sale_id"/>
+ <field name="invoice_user_id"/>
+ <field name="invoice_day_to_due"/>
+ <field name="new_invoice_day_to_due"/>
+ <field name="payment_state" widget="badge"
+ decoration-danger="payment_state == 'not_paid'"
+ decoration-warning="payment_state == 'partial'"/>
+ <field name="amount_total"/>
+ <field name="amount_residual"/>
+ <button name="action_create_surat_piutang"
+ type="object"
+ string="Create Surat Piutang"
+ class="oe_highlight"/>
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="view_unpaid_invoice_search" model="ir.ui.view">
+ <field name="name">unpaid.invoice.view.search</field>
+ <field name="model">unpaid.invoice.view</field>
+ <field name="arch" type="xml">
+ <search string="Search Unpaid Invoices">
+ <field name="partner_id"/>
+ <field name="invoice_number"/>
+ </search>
+ </field>
+ </record>
+
+ <!-- Action -->
+ <record id="action_unpaid_invoice_view" model="ir.actions.act_window">
+ <field name="name">Unpaid Invoices Monitoring</field>
+ <field name="res_model">unpaid.invoice.view</field>
+ <field name="view_mode">tree,form</field>
+ <field name="view_id" ref="view_unpaid_invoice_tree"/>
+ <field name="search_view_id" ref="view_unpaid_invoice_search"/>
+ </record>
+
+ <!-- Menu -->
+ <menuitem id="menu_unpaid_invoice_root"
+ name="Unpaid Invoices Monitoring"
+ parent="account.menu_finance_receivables"
+ action="action_unpaid_invoice_view"/>
+</odoo>