summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-28 15:06:26 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-28 15:06:26 +0700
commitb4fa8f4df995f946b642eda78ca5fc2b8badada2 (patch)
tree693c6595a2628ded19a4525da7530075cccbfde4
parent6983b0f81beb28b0df43c78e50dbcf310235a9dd (diff)
<hafid> fixing journal
-rw-r--r--indoteknik_custom/models/refund_sale_order.py32
-rwxr-xr-xindoteknik_custom/models/sale_order.py6
-rw-r--r--indoteknik_custom/views/refund_sale_order.xml6
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
4 files changed, 34 insertions, 12 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': '',
diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml
index 4f791722..0c4eaa56 100644
--- a/indoteknik_custom/views/refund_sale_order.xml
+++ b/indoteknik_custom/views/refund_sale_order.xml
@@ -66,7 +66,7 @@
string="Journal Refund"
type="object"
class="oe_highlight"
- attrs="{'invisible': ['|', ('status', 'not in', ['pengajuan3','refund']), ('journal_refund_state', '=', 'posted')]}"/>
+ attrs="{'invisible': [('journal_refund_state', '=', 'posted')]}"/>
<field name="status"
widget="statusbar"
@@ -117,8 +117,8 @@
<field name="note_refund" attrs="{'readonly': [('is_locked', '=', True)]}"/>
</group>
<group>
- <field name="uang_masuk" attrs="{'readonly': [('is_locked', '=', True)]}"/>
- <field name="total_invoice" attrs="{'readonly': [('is_locked', '=', True)]}"/>
+ <field name="uang_masuk" attrs="{'readonly': ['|', ('is_locked', '=', True), ('refund_type', '=', 'barang_kosong_sebagian')]}"/>
+ <field name="total_invoice" readonly="1"/>
<field name="ongkir" attrs="{'readonly': [('is_locked', '=', True)]}"/>
<field name="amount_refund" attrs="{'readonly': [('is_locked', '=', True)]}"/>
<field name="amount_refund_text" readonly="1"/>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 987303ba..08dcfbb7 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -40,7 +40,7 @@
type="object"
string="Refund"
class="btn-primary"
- attrs="{'invisible': ['|', ('state', 'not in', ['sale', 'done']), ('has_refund', '=', True)]}" />
+ attrs="{'invisible': [('has_refund', '=', 'True')]}" />
</xpath>
<div class="oe_button_box" name="button_box">
<field name="advance_payment_move_ids" invisible="1"/>