summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-09-16 10:04:16 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-09-16 10:04:16 +0000
commit940a2c02cfef4b4fa9fa56ed7887116795beab5b (patch)
tree18e9ae9a96c543c2977ad6853060a4c5b549dc24 /indoteknik_custom/models/sale_order.py
parent07d8129d96f1e48838e27c33ad762673a04d465e (diff)
parent9e6ab83ccd890c2ddd4e74cc0ed650d35a12f31e (diff)
Merged in refund_system (pull request #419)
<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 136663ba..484a9016 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -3261,16 +3261,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:
@@ -3279,12 +3294,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