From 1ca068669ba7e255e8a69d981aba513dcfeedd40 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 15 Sep 2025 16:23:48 +0700 Subject: fix validasi refund --- indoteknik_custom/models/refund_sale_order.py | 20 ++++++++++++++++++-- indoteknik_custom/views/refund_sale_order.xml | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index f511ed5d..9b14243b 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -56,6 +56,7 @@ class RefundSaleOrder(models.Model): refund_type = fields.Selection([ ('barang_kosong_sebagian', 'Refund Barang Kosong Sebagian'), + ('barang_kosong_indent', 'Refund Barang Kosong Jika ada Indent'), ('barang_kosong', 'Refund Barang Kosong Full'), ('uang', 'Refund Lebih Bayar'), ('retur_half', 'Refund Retur Sebagian'), @@ -77,7 +78,7 @@ class RefundSaleOrder(models.Model): 'account.move', string="Journal Payment", copy=False, - help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO." + help="Pilih transaksi salah transfer dari jurnal Uang Muka yang tidak terkait SO." ) tukar_guling_count = fields.Integer( @@ -297,6 +298,14 @@ class RefundSaleOrder(models.Model): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 vals['total_invoice'] = total_invoice amount_refund = vals.get('amount_refund', 0.0) + can_refund = sisa_uang_masuk - total_invoice + + if can_refund > amount_refund or can_refund == 0.0: + raise ValidationError( + _("Maksimal refund yang bisa dilakukan adalah sebesar %s. " + "Silakan sesuaikan jumlah refund.") % (can_refund) + ) + if amount_refund <= 0.00: raise ValidationError('Total Refund harus lebih dari 0 jika ingin mengajukan refund') @@ -393,9 +402,16 @@ class RefundSaleOrder(models.Model): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) vals['total_invoice'] = total_invoice uang_masuk = rec.uang_masuk + can_refund = uang_masuk - total_invoice amount_refund = vals.get('amount_refund', rec.amount_refund) + if amount_refund > can_refund: + raise ValidationError( + _("Maksimal refund yang bisa dilakukan adalah sebesar %s. " + "Silakan sesuaikan jumlah refund.") % (can_refund) + ) + if amount_refund <= 0: raise ValidationError("Total Refund harus lebih dari 0.") @@ -829,7 +845,7 @@ class RefundSaleOrder(models.Model): # Normalisasi refund_type_label = refund_type_label.upper() - if refund.refund_type in ['barang_kosong', 'barang_kosong_sebagian']: + if refund.refund_type in ['barang_kosong', 'barang_kosong_sebagian', 'barang_kosong_indent']: refund_type_label = "REFUND BARANG KOSONG" elif refund.refund_type in ['retur_half', 'retur']: refund_type_label = "REFUND RETUR BARANG" diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml index 0c6cd371..51f3deab 100644 --- a/indoteknik_custom/views/refund_sale_order.xml +++ b/indoteknik_custom/views/refund_sale_order.xml @@ -92,7 +92,7 @@ -- cgit v1.2.3