diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-09-15 16:23:48 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-09-15 16:23:48 +0700 |
| commit | 1ca068669ba7e255e8a69d981aba513dcfeedd40 (patch) | |
| tree | 4e3f7863eaf7cb55de437f992fec84dda60d53c0 | |
| parent | fb069315f937ea1a8a094d23f22f8314cef412a4 (diff) | |
<hafid> fix validasi refund
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 20 | ||||
| -rw-r--r-- | 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 @@ </div> <field name="show_approval_alert" invisible="1"/> <div class="alert alert-info" role="alert" - attrs="{'invisible': ['|', ('show_approval_alert', '=', False), ('status', 'in', ['reject', 'refund'])]}"> + attrs="{'invisible': ['|', ('show_approval_alert', '=', False), '|', ('status', 'in', ['reject', 'refund']), ('refund_type', 'not in', ['retur_full', 'retur_sebagian'])]}"> ⚠️ SO sudah melakukan retur barang. Silakan lanjutkan refund. </div> </xpath> |
