summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-09-02 05:05:59 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-09-02 05:05:59 +0000
commit5a6ea1188feb8d1406ba0e90464045324855de56 (patch)
tree66afaf6e3224519435913717d161d275c2f14d9b
parent4c2decb6938e1920cf330dd8210bebf9ab3669b7 (diff)
parent5b601ca1ff1a669b934b69b8f531573866a13ed0 (diff)
Merged in refund_system (pull request #399)
<hafid> fix refund ongkir
-rw-r--r--indoteknik_custom/models/refund_sale_order.py29
1 files changed, 8 insertions, 21 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py
index 6d0b5741..737419e7 100644
--- a/indoteknik_custom/models/refund_sale_order.py
+++ b/indoteknik_custom/models/refund_sale_order.py
@@ -392,6 +392,7 @@ 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
+
amount_refund = vals.get('amount_refund', rec.amount_refund)
if amount_refund <= 0:
@@ -401,36 +402,22 @@ class RefundSaleOrder(models.Model):
('sale_order_ids', 'in', so_ids),
('id', '!=', rec.id)
])
- total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund
- remaining = uang_masuk - total_refunded
+ total_refunded = sum(existing_refunds.mapped('amount_refund'))
+ if existing_refunds:
+ remaining = uang_masuk - total_refunded
+ else:
+ remaining = uang_masuk - amount_refund
- if remaining < 0:
- raise ValidationError("❌ Dana uang masuk telah sepenuhnya di refund tidak bisa Mengubah Nominal Refund")
vals['remaining_refundable'] = remaining
return super().write(vals)
- @api.onchange('ongkir', 'amount_refund')
+ @api.onchange('amount_refund')
def _onchange_refund_fields(self):
for rec in self:
refund_input = rec.amount_refund or 0.0
-
- # ambil refund terakhir untuk SO
- existing_refund = self.env['refund.sale.order'].search([
- ('sale_order_ids', 'in', rec.sale_order_ids.ids)
- ], order='id desc', limit=1)
-
- if existing_refund:
- sisa_uang_masuk = existing_refund.remaining_refundable
- else:
- sisa_uang_masuk = rec.uang_masuk or 0.0
-
- # update field uang_masuk supaya form menampilkan sisa aktual
- rec.uang_masuk = sisa_uang_masuk
-
- # hitung remaining setelah input refund
- rec.remaining_refundable = sisa_uang_masuk - refund_input
+ rec.remaining_refundable = (rec.uang_masuk or 0.0) - refund_input
@api.depends('status_payment', 'status')
def _compute_is_locked(self):