summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/refund_sale_order.py32
-rwxr-xr-xindoteknik_custom/models/sale_order.py6
2 files changed, 30 insertions, 8 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py
index 2a55f16d..80d66d8d 100644
--- a/indoteknik_custom/models/refund_sale_order.py
+++ b/indoteknik_custom/models/refund_sale_order.py
@@ -124,7 +124,7 @@ class RefundSaleOrder(models.Model):
self.env.user.has_group('indoteknik_custom.group_role_fat') or
self.env.user.id not in allowed_user_ids
):
- raise UserError("❌ Hanya user Sales dan Finance yang boleh membuat refund.")
+ raise UserError("❌ Hanya Sales dan Finance yang boleh membuat refund.")
if vals.get('name', 'New') == 'New':
@@ -150,13 +150,18 @@ class RefundSaleOrder(models.Model):
refund_type = vals.get('refund_type')
invoice_ids_data = vals.get('invoice_ids', [])
invoice_ids = invoice_ids_data[0][2] if invoice_ids_data and invoice_ids_data[0][0] == 6 else []
-
if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']:
raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian jika ada invoice")
- if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']:
+ if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'retur_half']:
raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian Hanya Bisa dipilih Jika Ada Invoice")
+ if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and so_ids:
+ sale_orders = self.env['sale.order'].browse(so_ids)
+ zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0)
+ if not zero_delivery_lines:
+ raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.")
+
if not so_ids and refund_type != 'lainnya':
raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Lainnya'.")
@@ -180,6 +185,10 @@ class RefundSaleOrder(models.Model):
ongkir = vals.get('ongkir', 0.0)
pengurangan = total_invoice + ongkir
+ if refund_type == 'barang_kosong_sebagian' and so_ids:
+ sale_orders = self.env['sale.order'].browse(so_ids)
+ vals['uang_masuk'] = sum(sale_orders.mapped('amount_total'))
+
if uang_masuk > pengurangan:
vals['amount_refund'] = uang_masuk - pengurangan
else:
@@ -229,8 +238,16 @@ class RefundSaleOrder(models.Model):
refund_type = vals.get('refund_type', rec.refund_type)
+ if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and sale_orders:
+ zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0)
+ if not zero_delivery_lines:
+ raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.")
+
if not so_ids and refund_type != 'lainnya':
raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Lainnya'.")
+
+ if refund_type == 'barang_kosong_sebagian' and sale_orders:
+ vals['uang_masuk'] = sum(sale_orders.mapped('amount_total'))
invoice_ids = vals.get('invoice_ids', False)
@@ -248,7 +265,7 @@ class RefundSaleOrder(models.Model):
if invoice_ids and vals.get('refund_type', rec.refund_type) not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']:
raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian jika ada invoice")
- if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']:
+ if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian', 'retur_half']:
raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian Hanya Bisa dipilih Jika Ada Invoice")
if refund_type in ['retur', 'retur_half'] and so_ids:
@@ -358,6 +375,9 @@ class RefundSaleOrder(models.Model):
self.line_ids = line_vals
+ if self.refund_type == 'barang_kosong_sebagian' and self.sale_order_ids:
+ self.uang_masuk = sum(self.sale_order_ids.mapped('amount_total')) + sum(self.sale_order_ids.mapped('delivery_amt'))
+
elif self.refund_type in ['retur', 'retur_half'] and self.sale_order_ids:
line_vals = []
StockPicking = self.env['stock.picking']
@@ -586,8 +606,8 @@ class RefundSaleOrder(models.Model):
})
amount = refund.amount_refund
-
- second_account_id = 450 if has_invoice else 668
+ # 450 Penerimaan Belum Teridentifikasi, 668 Penerimaan Belum Alokasi
+ second_account_id = 450 if refund.refund_type not in ['barang_kosong', 'barang_kosong_sebagian'] else 668
debit_line = {
'move_id': account_move.id,
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 4d0b1d7b..46dad6ff 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -3111,6 +3111,7 @@ class SaleOrder(models.Model):
self.ensure_one()
invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel')
+ total_so = sum(self.mapped('amount_total'))
return {
'name': 'Refund Sale Order',
@@ -3121,7 +3122,7 @@ class SaleOrder(models.Model):
'context': {
'default_sale_order_ids': [(6, 0, [self.id])],
'default_invoice_ids': [(6, 0, invoice_ids.ids)],
- 'default_uang_masuk': sum(invoice_ids.mapped('amount_total')) + (self.delivery_amt or 0.0) + 1000,
+ 'default_uang_masuk': total_so,
'default_ongkir': self.delivery_amt or 0.0,
'default_bank': '', # bisa isi default bank kalau mau
'default_account_name': '',
@@ -3150,6 +3151,7 @@ class SaleOrder(models.Model):
invoice_ids = self.mapped('invoice_ids').filtered(lambda inv: inv.state != 'cancel')
delivery_total = sum(self.mapped('delivery_amt'))
total_invoice = sum(invoice_ids.mapped('amount_total_signed'))
+ total_so = sum(self.mapped('amount_total'))
return {
'type': 'ir.actions.act_window',
@@ -3160,7 +3162,7 @@ class SaleOrder(models.Model):
'context': {
'default_sale_order_ids': [(6, 0, self.ids)],
'default_invoice_ids': [(6, 0, invoice_ids.ids)],
- 'default_uang_masuk': total_invoice + delivery_total + 1000,
+ 'default_uang_masuk': total_so,
'default_ongkir': delivery_total,
'default_bank': '',
'default_account_name': '',