diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-09-16 09:11:18 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-09-16 09:11:18 +0700 |
| commit | af7fc5db50d7c3f78b70a2b75186db4b4c1f3674 (patch) | |
| tree | a373827d750fcc0035c0b91a909b4d8b271c485e /indoteknik_custom/models/refund_sale_order.py | |
| parent | ee9dab9b220b63e4c018a63aeea37a47895704ae (diff) | |
| parent | 78a4f924fa9ba38c58954b5840632806b04fff19 (diff) | |
<Miqdad> merge
Diffstat (limited to 'indoteknik_custom/models/refund_sale_order.py')
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 731d8e41..55128080 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -76,7 +76,8 @@ class RefundSaleOrder(models.Model): transfer_move_id = fields.Many2one( 'account.move', string="Journal Payment", - help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO." + copy=False, + help="Pilih transaksi salah transfer dari jurnal Uang Muka yang tidak terkait SO." ) tukar_guling_count = fields.Integer( @@ -296,6 +297,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 amount_refund > can_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') @@ -392,9 +401,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.") @@ -462,7 +478,7 @@ class RefundSaleOrder(models.Model): total_invoice = 0.0 so_ids = self.sale_order_ids.ids - + amount_refund_before = 0.0 for so in self.sale_order_ids: self.ongkir += so.delivery_amt or 0.0 valid_invoices = so.invoice_ids.filtered( @@ -470,6 +486,10 @@ class RefundSaleOrder(models.Model): ) all_invoices |= valid_invoices total_invoice += sum(valid_invoices.mapped('amount_total_signed')) + refunds = self.env['refund.sale.order'].search([ + ('sale_order_ids', 'in', so_ids) + ]) + amount_refund_before += sum(refunds.mapped('amount_refund')) if refunds else 0.0 moves = self.env['account.move'].search([ ('sale_id', 'in', so_ids), @@ -478,7 +498,7 @@ class RefundSaleOrder(models.Model): ]) total_uang_muka = sum(moves.mapped('amount_total_signed')) if moves else 0.0 total_midtrans = sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) if so_ids else 0.0 - self.uang_masuk = total_uang_muka + total_midtrans + self.uang_masuk = (total_uang_muka + total_midtrans) - amount_refund_before self.invoice_ids = all_invoices @@ -819,15 +839,26 @@ class RefundSaleOrder(models.Model): # Ambil label refund type refund_type_label = dict( self.fields_get(allfields=['refund_type'])['refund_type']['selection'] - ).get(refund.refund_type, '').replace("Refund ", "").upper() - + ).get(refund.refund_type, '') + + # Normalisasi + refund_type_label = refund_type_label.upper() + + if refund.refund_type in ['barang_kosong', 'barang_kosong_sebagian']: + refund_type_label = "REFUND BARANG KOSONG" + elif refund.refund_type in ['retur_half', 'retur']: + refund_type_label = "REFUND RETUR BARANG" + elif refund.refund_type == 'uang': + refund_type_label = "REFUND LEBIH BAYAR" + elif refund.refund_type == 'salah_transfer': + refund_type_label = "REFUND SALAH TRANSFER" if not partner: raise UserError("❌ Partner tidak ditemukan.") # Ref format - ref_text = f"REFUND {refund_type_label} {refund.name or ''} {partner.display_name}".upper() + ref_text = f"{refund_type_label} {refund.name or ''} {partner.display_name}".upper() # Buat Account Move (Journal Entry) account_move = self.env['account.move'].create({ @@ -877,7 +908,8 @@ class RefundSaleOrder(models.Model): def _compute_journal_refund_move_id(self): for rec in self: move = self.env['account.move'].search([ - ('refund_id', '=', rec.id) + ('refund_id', '=', rec.id), + ('state', '!=', 'cancel') ], limit=1) rec.journal_refund_move_id = move |
