summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-09-16 21:48:17 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-09-16 21:48:17 +0700
commit0a117ae984dafdb9c160e3fea4d1aac0ddfd164e (patch)
tree6223cbfa6e270321a23b6be18d5a6ea22138671b /indoteknik_custom/models/sale_order.py
parent1f63169f38675adf23a1e4a66b31711f90721f39 (diff)
parent6791235591714e4ac45a6729409716bcba9e8fea (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into cbd-apt
merge
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 2ae2d647..bbcb9531 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1674,7 +1674,7 @@ class SaleOrder(models.Model):
rec.expected_ready_to_ship = eta_date
@api.depends("order_line.product_id", "date_order")
- def _compute_etrts_date(self): # Function to calculate Estimated Ready To Ship Date
+ def _compute_etrts_date(self):
self._calculate_etrts_date()
@@ -1844,9 +1844,9 @@ class SaleOrder(models.Model):
def override_allow_create_invoice(self):
if not self.env.user.is_accounting:
raise UserError('Hanya Finance Accounting yang dapat klik tombol ini')
- for term in self.payment_term_id.line_ids:
- if term.days > 0:
- raise UserError('Hanya dapat digunakan pada Cash Before Delivery')
+ # for term in self.payment_term_id.line_ids:
+ # if term.days > 0:
+ # raise UserError('Hanya dapat digunakan pada Cash Before Delivery')
for line in self.order_line:
line.qty_to_invoice = line.product_uom_qty
@@ -2650,7 +2650,7 @@ class SaleOrder(models.Model):
if user.is_leader or user.is_sales_manager:
return True
- if user.id in (3401, 20, 3988): # admin (fida, nabila, ninda)
+ if user.id in (3401, 20, 3988, 17340): # admin (fida, nabila, ninda)
return True
if self.env.context.get("ask_approval") and user.id in (3401, 20, 3988):
@@ -3267,16 +3267,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:
@@ -3285,12 +3300,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