summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-09-16 16:18:24 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-09-16 16:18:24 +0700
commit9e6ab83ccd890c2ddd4e74cc0ed650d35a12f31e (patch)
treeb7eff048b7843b7be7e0e6e407012c5f6c0c5eeb /indoteknik_custom/models/sale_order.py
parent41b9e8084b388dca0b5b18daf0dfe9537db1ed1c (diff)
<hafid> journal payment tempo
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 76d4d7e7..9cdd9a7b 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -3306,16 +3306,31 @@ class SaleOrder(models.Model):
f"❌ SO {self.name} Belum melakukan kirim barang "
f"({', '.join(not_done_pickings.mapped('name'))}). Selesaikan Pengiriman untuk melakukan refund."
)
+
+ invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel')
+
moves = self.env['account.move'].search([
('sale_id', '=', self.id),
('journal_id', '=', 11),
('state', '=', 'posted'),
])
+ piutangbca = self.env['account.move'].search([
+ ('ref', 'in', invoice_ids.mapped('name')),
+ ('journal_id', '=', 4),
+ ('state', '=', 'posted'),
+ ])
+ piutangmdr = self.env['account.move'].search([
+ ('ref', 'in', invoice_ids.mapped('name')),
+ ('journal_id', '=', 7),
+ ('state', '=', 'posted'),
+ ])
# Default 0
total_uang_muka = 0.0
has_moves = bool(moves)
+ has_piutangmdr = bool(piutangmdr)
+ has_piutangbca = bool(piutangbca)
has_settlement = self.payment_status == 'settlement'
if has_moves and has_settlement:
@@ -3324,12 +3339,15 @@ class SaleOrder(models.Model):
total_uang_muka = sum(moves.mapped('amount_total_signed'))
elif has_settlement:
total_uang_muka = self.gross_amount
+ elif has_piutangbca:
+ total_uang_muka = sum(piutangbca.mapped('amount_total_signed'))
+ elif has_piutangmdr:
+ total_uang_muka = sum(piutangmdr.mapped('amount_total_signed'))
else:
raise UserError(
"Tidak bisa melakukan refund karena SO tidak memiliki Record Uang Masuk "
- "(Journal Uang Muka/Midtrans Payment)."
+ "(Journal Uang Muka/Payment Invoices/Midtrans Payment)."
)
- invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel')
total_refunded = sum(self.refund_ids.mapped('amount_refund'))
sisa_uang_muka = total_uang_muka - total_refunded