summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/refund_sale_order.py
diff options
context:
space:
mode:
authorFIN-IT_AndriFP <it@fixcomart.co.id>2025-10-02 14:04:56 +0700
committerFIN-IT_AndriFP <it@fixcomart.co.id>2025-10-02 14:04:56 +0700
commit7d89516ce05d0ea67733c04436cc2de544189efe (patch)
tree2521fbf09f4695253fd7db1ff7613b7f003f20ea /indoteknik_custom/models/refund_sale_order.py
parent10da5e27e658030f171f694d6696f93e4a472447 (diff)
parent875b20796c7fa64abebe430b2707df597e29836b (diff)
Merge branch 'pum-v2' of https://bitbucket.org/altafixco/indoteknik-addons into pum-v2
Diffstat (limited to 'indoteknik_custom/models/refund_sale_order.py')
-rw-r--r--indoteknik_custom/models/refund_sale_order.py333
1 files changed, 295 insertions, 38 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py
index 9ab18f27..de9870f6 100644
--- a/indoteknik_custom/models/refund_sale_order.py
+++ b/indoteknik_custom/models/refund_sale_order.py
@@ -51,12 +51,14 @@ class RefundSaleOrder(models.Model):
account_no = fields.Char(string='Account No', required=True)
kcp = fields.Char(string='Alamat KCP')
finance_note = fields.Text(string='Finance Note')
+ biaya_admin = fields.Float(string='Biaya Admin Transfer')
invoice_names = fields.Html(string="Group Invoice Number", compute="_compute_invoice_names")
so_names = fields.Html(string="Group SO Number", compute="_compute_so_names")
refund_type = fields.Selection([
('barang_kosong_sebagian', 'Refund Barang Kosong Sebagian'),
('barang_kosong', 'Refund Barang Kosong Full'),
+ ('barang_kosong_indent', 'Refund Barang Kosong Sebagian(Indent)'),
('uang', 'Refund Lebih Bayar'),
('retur_half', 'Refund Retur Sebagian'),
('retur', 'Refund Retur Full'),
@@ -77,7 +79,7 @@ class RefundSaleOrder(models.Model):
'account.move',
string="Journal Payment",
copy=False,
- help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO."
+ help="Pilih transaksi salah transfer dari jurnal Uang Muka yang tidak terkait SO."
)
tukar_guling_count = fields.Integer(
@@ -113,7 +115,7 @@ class RefundSaleOrder(models.Model):
string='Customer',
required=True
)
- advance_move_names = fields.Html(string="Group Journal SO", compute="_compute_advance_move_names")
+ advance_move_names = fields.Html(string="Group Journal Payment", compute="_compute_advance_move_names")
uang_masuk_type = fields.Selection([
('pdf', 'PDF'),
('image', 'Image'),
@@ -216,7 +218,7 @@ class RefundSaleOrder(models.Model):
vals['created_date'] = fields.Date.context_today(self)
vals['create_uid'] = self.env.user.id
-
+ refund_type = vals.get('refund_type')
if 'sale_order_ids' in vals:
so_cmd = vals['sale_order_ids']
so_ids = so_cmd[0][2] if so_cmd and so_cmd[0][0] == 6 else []
@@ -226,6 +228,18 @@ class RefundSaleOrder(models.Model):
if len(partner) > 1:
raise UserError("❌ Tidak dapat membuat refund untuk Multi SO dengan Customer berbeda. Harus memiliki Customer yang sama.")
vals['partner_id'] = sale_orders[0].partner_id.id
+ if refund_type not in ['barang_kosong_indent', 'salah_transfer']:
+ for so in sale_orders:
+ if so.state not in ['cancel', 'sale']:
+ raise UserError(f"❌ SO {so.name} tidak bisa direfund. Status harus Cancel atau Sale.")
+ if so.state == 'sale':
+ not_done_pickings = so.picking_ids.filtered(lambda p: p.state not in ['done', 'cancel'])
+ if not_done_pickings:
+ raise UserError(
+ f"❌ SO {so.name} Belum melakukan kirim barang "
+ f"({', '.join(not_done_pickings.mapped('name'))}). "
+ "Selesaikan Pengiriman untuk melakukan refund."
+ )
invoices = sale_orders.mapped('invoice_ids').filtered(
lambda inv: inv.move_type in ['out_invoice', 'out_refund'] and inv.state != 'cancel'
@@ -234,16 +248,16 @@ class RefundSaleOrder(models.Model):
vals['invoice_ids'] = [(6, 0, invoices.ids)]
- 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 []
+ invoices = self.env['account.move'].browse(invoice_ids)
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 jika ada invoice")
if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'retur_half']:
raise UserError("Refund type Lebih Bayar dan Barang Kosong Sebagian Hanya Bisa dipilih Jika Ada Invoice")
- if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and so_ids:
+ if refund_type in ['barang_kosong', 'barang_kosong_sebagian', 'barang_kosong_indent'] and so_ids:
sale_orders = self.env['sale.order'].browse(so_ids)
if refund_type == 'barang_kosong':
@@ -267,8 +281,11 @@ class RefundSaleOrder(models.Model):
if refund_type == 'salah_transfer' and vals.get('transfer_move_id'):
move = self.env['account.move'].browse(vals['transfer_move_id'])
if move:
+ sisa_uang_masuk = move.amount_total_signed # ← set dengan nilai move
vals['uang_masuk'] = move.amount_total_signed
vals['remaining_refundable'] = 0
+ else:
+ sisa_uang_masuk = 0.0
else:
# ==== perhitungan normal ====
moves = self.env['account.move'].search([
@@ -276,18 +293,81 @@ class RefundSaleOrder(models.Model):
('journal_id', '=', 11),
('state', '=', 'posted'),
])
- total_uang_muka = sum(moves.mapped('amount_total_signed')) if moves else 0.0
- total_midtrans = sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) if so_ids else 0.0
- total_pembayaran = total_uang_muka + total_midtrans
+ piutangbca = self.env['account.move'].search([
+ ('ref', 'in', invoices.mapped('name')),
+ ('journal_id', '=', 4),
+ ('state', '=', 'posted'),
+ ])
+ piutangmdr = self.env['account.move'].search([
+ ('ref', 'in', invoices.mapped('name')),
+ ('journal_id', '=', 7),
+ ('state', '=', 'posted'),
+ ])
+
+ misc = self.env['account.move'].search([
+ ('ref', 'ilike', invoices.mapped('name')[0]),
+ ('ref', 'not ilike', 'reklas'),
+ ('journal_id', '=', 13),
+ ('state', '=', 'posted'),
+ ])
+ moves2 = self.env['account.move']
+ if so_ids:
+ so_names = self.env['sale.order'].browse(so_ids).mapped('name')
+ domain = [
+ ('journal_id', '=', 11),
+ ('state', '=', 'posted'),
+ ('ref', 'ilike', 'dp')
+ ]
+ if so_names:
+ domain += ['|'] * (len(so_names) - 1)
+ for n in so_names:
+ domain.append(('ref', 'ilike', n))
+ moves2 = self.env['account.move'].search(domain)
+
+ has_moves = bool(moves)
+ has_moves2 = bool(moves2)
+ has_piutangmdr = bool(piutangmdr)
+ has_piutangbca = bool(piutangbca)
+ has_misc = bool(misc)
+ ssos = self.env['sale.order'].browse(so_ids)
+ has_settlement = any(so.payment_status == 'settlement' for so in ssos)
+
+ sisa_uang_masuk = 0.0
+ amounts = []
+ if has_moves and has_settlement:
+ amounts.append(sum(moves.mapped('amount_total_signed')))
+ amounts.append(sum(ssos.mapped('gross_amount')))
+ else:
+ if has_moves:
+ amounts.append(sum(moves.mapped('amount_total_signed')))
+ if has_settlement:
+ amounts.append(sum(ssos.mapped('gross_amount')))
+
+ # sisanya bisa dijumlahkan tanpa konflik
+ if has_moves2:
+ amounts.append(sum(moves2.mapped('amount_total_signed')))
+ if has_piutangbca:
+ amounts.append(sum(piutangbca.mapped('amount_total_signed')))
+ if has_piutangmdr:
+ amounts.append(sum(piutangmdr.mapped('amount_total_signed')))
+ if has_misc:
+ amounts.append(sum(misc.mapped('amount_total_signed')))
+
+ sisa_uang_masuk = sum(amounts)
+
+ if not sisa_uang_masuk:
+ raise UserError(
+ "❌ Tidak bisa melakukan refund karena SO tidak memiliki Record Uang Masuk "
+ "(Journal Uang Muka / Payment Invoices / Midtrans Payment)."
+ )
+
existing_refunds = self.env['refund.sale.order'].search([
('sale_order_ids', 'in', so_ids)
], order='id desc', limit=1)
if existing_refunds:
sisa_uang_masuk = existing_refunds.remaining_refundable
- else:
- sisa_uang_masuk = total_pembayaran
if sisa_uang_masuk < 0:
raise UserError("❌ Tidak ada sisa transaksi untuk di-refund.")
@@ -297,6 +377,14 @@ class RefundSaleOrder(models.Model):
total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0
vals['total_invoice'] = total_invoice
amount_refund = vals.get('amount_refund', 0.0)
+ can_refund = sisa_uang_masuk - total_invoice
+
+ if amount_refund > can_refund or can_refund == 0.0:
+ raise ValidationError(
+ _("Maksimal refund yang bisa dilakukan adalah sebesar %s. "
+ "Silakan sesuaikan jumlah refund.") % (can_refund)
+ )
+
if amount_refund <= 0.00:
raise ValidationError('Total Refund harus lebih dari 0 jika ingin mengajukan refund')
@@ -345,6 +433,7 @@ class RefundSaleOrder(models.Model):
sale_orders = self.env['sale.order'].browse(so_ids)
+
valid_invoices = sale_orders.mapped('invoice_ids').filtered(
lambda inv: inv.move_type in ['out_invoice', 'out_refund'] and inv.state != 'cancel'
)
@@ -354,9 +443,19 @@ class RefundSaleOrder(models.Model):
so_ids = rec.sale_order_ids.ids
sale_orders = self.env['sale.order'].browse(so_ids)
-
-
refund_type = vals.get('refund_type', rec.refund_type)
+ if refund_type not in ['barang_kosong_indent', 'salah_transfer']:
+ for so in sale_orders:
+ if so.state not in ['cancel', 'sale']:
+ raise UserError(f"❌ SO {so.name} tidak bisa direfund. Status harus Cancel atau Sale.")
+ if so.state == 'sale':
+ not_done_pickings = so.picking_ids.filtered(lambda p: p.state not in ['done', 'cancel'])
+ if not_done_pickings:
+ raise UserError(
+ f"❌ SO {so.name} Belum melakukan kirim barang "
+ f"({', '.join(not_done_pickings.mapped('name'))}). "
+ "Selesaikan Pengiriman untuk melakukan refund."
+ )
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 or l.product_uom_qty > l.qty_delivered)
@@ -393,9 +492,16 @@ class RefundSaleOrder(models.Model):
total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed'))
vals['total_invoice'] = total_invoice
uang_masuk = rec.uang_masuk
+ can_refund = uang_masuk - total_invoice
amount_refund = vals.get('amount_refund', rec.amount_refund)
+ if amount_refund > can_refund:
+ raise ValidationError(
+ _("Maksimal refund yang bisa dilakukan adalah sebesar %s. "
+ "Silakan sesuaikan jumlah refund.") % (can_refund)
+ )
+
if amount_refund <= 0:
raise ValidationError("Total Refund harus lebih dari 0.")
@@ -437,15 +543,59 @@ class RefundSaleOrder(models.Model):
def _compute_advance_move_names(self):
for rec in self:
move_links = []
+
+ invoice_ids = rec.sale_order_ids.mapped('invoice_ids')
+
moves = self.env['account.move'].search([
('sale_id', 'in', rec.sale_order_ids.ids),
('journal_id', '=', 11),
- ('state', '=', 'posted')
+ ('state', '=', 'posted'),
])
- for move in moves:
+
+ 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'),
+ ])
+
+ moves2 = self.env['account.move']
+ if rec.sale_order_ids:
+ so_names = rec.sale_order_ids.mapped('name')
+
+ domain = [
+ ('journal_id', '=', 11),
+ ('state', '=', 'posted'),
+ ('ref', 'ilike', 'dp')
+ ]
+ domain += ['|'] * (len(so_names) - 1)
+ for n in so_names:
+ domain.append(('ref', 'ilike', n))
+
+ moves2 = self.env['account.move'].search(domain)
+
+ misc = self.env['account.move']
+ if invoice_ids:
+ invoice_name = invoice_ids.mapped('name')[0]
+ misc = self.env['account.move'].search([
+ ('ref', 'ilike', invoice_name),
+ ('ref', 'not ilike', 'reklas'),
+ ('journal_id', '=', 13),
+ ('state', '=', 'posted'),
+ ])
+
+ all_moves = moves | piutangbca | piutangmdr | misc | moves2
+
+ for move in all_moves:
url = f"/web#id={move.id}&model=account.move&view_type=form"
name = html_escape(move.name or 'Unnamed')
move_links.append(f'<a href="{url}" target="_blank">{name}</a>')
+
rec.advance_move_names = ', '.join(move_links) if move_links else "-"
@api.depends('sale_order_ids.user_id')
@@ -463,7 +613,7 @@ class RefundSaleOrder(models.Model):
total_invoice = 0.0
so_ids = self.sale_order_ids.ids
-
+ amount_refund_before = 0.0
for so in self.sale_order_ids:
self.ongkir += so.delivery_amt or 0.0
valid_invoices = so.invoice_ids.filtered(
@@ -471,15 +621,76 @@ class RefundSaleOrder(models.Model):
)
all_invoices |= valid_invoices
total_invoice += sum(valid_invoices.mapped('amount_total_signed'))
+ refunds = self.env['refund.sale.order'].search([
+ ('sale_order_ids', 'in', so_ids)
+ ])
+ amount_refund_before += sum(refunds.mapped('amount_refund')) if refunds else 0.0
moves = self.env['account.move'].search([
('sale_id', 'in', so_ids),
('journal_id', '=', 11),
('state', '=', 'posted'),
])
- total_uang_muka = sum(moves.mapped('amount_total_signed')) if moves else 0.0
- total_midtrans = sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) if so_ids else 0.0
- self.uang_masuk = total_uang_muka + total_midtrans
+ piutangbca = self.env['account.move'].search([
+ ('ref', 'in', all_invoices.mapped('name')),
+ ('journal_id', '=', 4),
+ ('state', '=', 'posted'),
+ ])
+ piutangmdr = self.env['account.move'].search([
+ ('ref', 'in', all_invoices.mapped('name')),
+ ('journal_id', '=', 7),
+ ('state', '=', 'posted'),
+ ])
+ misc = self.env['account.move'].search([
+ ('ref', 'ilike', all_invoices.mapped('name')[0]),
+ ('ref', 'not ilike', 'reklas'),
+ ('journal_id', '=', 13),
+ ('state', '=', 'posted'),
+ ])
+ moves2 = self.env['account.move']
+ if so_ids:
+ so_records = self.env['sale.order'].browse(so_ids)
+ so_names = so_records.mapped('name')
+
+ domain = [
+ ('journal_id', '=', 11),
+ ('state', '=', 'posted'),
+ ('ref', 'ilike', 'dp')
+ ]
+ domain += ['|'] * (len(so_names) - 1)
+ for n in so_names:
+ domain.append(('ref', 'ilike', n))
+
+ moves2 = self.env['account.move'].search(domain)
+
+ has_moves = bool(moves)
+ has_moves2 = bool(moves2)
+ has_piutangmdr = bool(piutangmdr)
+ has_piutangbca = bool(piutangbca)
+ has_misc = bool(misc)
+ ssos = self.env['sale.order'].browse(so_ids)
+ has_settlement = any(so.payment_status == 'settlement' for so in ssos)
+
+ sisa_uang_masuk = 0.0
+
+ amounts = []
+
+ if has_moves:
+ amounts.append(sum(moves.mapped('amount_total_signed')))
+ if has_moves2:
+ amounts.append(sum(moves2.mapped('amount_total_signed')))
+ if has_piutangbca:
+ amounts.append(sum(piutangbca.mapped('amount_total_signed')))
+ if has_piutangmdr:
+ amounts.append(sum(piutangmdr.mapped('amount_total_signed')))
+ if has_misc:
+ amounts.append(sum(misc.mapped('amount_total_signed')))
+ if has_settlement:
+ amounts.append(sum(ssos.mapped('gross_amount')))
+
+ sisa_uang_masuk = sum(amounts)
+
+ self.uang_masuk = sisa_uang_masuk - amount_refund_before
self.invoice_ids = all_invoices
@@ -500,7 +711,6 @@ class RefundSaleOrder(models.Model):
""" Validasi SO harus punya uang masuk (Journal Uang Muka / Midtrans) """
for rec in self:
invalid_orders = []
- total_uang_masuk = 0.0
for so in rec.sale_order_ids:
# cari journal uang muka
@@ -509,28 +719,31 @@ class RefundSaleOrder(models.Model):
('journal_id', '=', 11), # Journal Uang Muka
('state', '=', 'posted'),
])
+ piutangbca = self.env['account.move'].search([
+ ('ref', 'in', rec.invoice_ids.mapped('name')),
+ ('journal_id', '=', 4),
+ ('state', '=', 'posted'),
+ ])
+ piutangmdr = self.env['account.move'].search([
+ ('ref', 'in', rec.invoice_ids.mapped('name')),
+ ('journal_id', '=', 7),
+ ('state', '=', 'posted'),
+ ])
- if not moves and so.payment_status != 'settlement':
+ if not moves and so.payment_status != 'settlement' and not piutangbca and not piutangmdr:
invalid_orders.append(so.name)
- if moves:
- total_uang_muka = sum(moves.mapped('amount_total_signed')) or 0.0
- total_uang_masuk += total_uang_muka
- else:
- # fallback Midtrans gross_amount
- total_uang_masuk += so.gross_amount or 0.0
-
if invalid_orders:
raise ValidationError(
f"Tidak dapat membuat refund untuk SO {', '.join(invalid_orders)} "
- "karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Midtrans).\n"
+ "karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Payment Invoice/Midtrans).\n"
"Pastikan semua SO yang dipilih sudah memiliki Record pembayaran yang valid."
)
@api.onchange('refund_type')
def _onchange_refund_type(self):
self.line_ids = [(5, 0, 0)]
- if self.refund_type in ['barang_kosong_sebagian', 'barang_kosong'] and self.sale_order_ids:
+ if self.refund_type in ['barang_kosong_sebagian', 'barang_kosong', 'barang_kosong_indent'] and self.sale_order_ids:
line_vals = []
for so in self.sale_order_ids:
for line in so.order_line:
@@ -741,7 +954,7 @@ class RefundSaleOrder(models.Model):
if not rec.status or rec.status == 'draft':
rec.status = 'pengajuan1'
- elif rec.status == 'pengajuan1' and self.env.user.id == 19:
+ elif rec.status == 'pengajuan1' and self.env.user.id in [19, 28]:
rec.status = 'pengajuan2'
rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name
rec.date_approved_sales = now
@@ -784,6 +997,15 @@ class RefundSaleOrder(models.Model):
for rec in self:
if not is_fat:
raise UserError("Hanya Finance yang dapat mengkonfirmasi pembayaran refund.")
+ is_journal = self.env['account.move'].search([
+ ('refund_id', '=', rec.id),
+ ('state', '=', 'posted')
+ ])
+ amount = rec.amount_refund + rec.biaya_admin
+ if not is_journal:
+ raise UserError("Journal Payment Refund belum dibuat, buat Journal Payment Refund sebelum confirm refund.")
+ if is_journal and amount != sum(is_journal.mapped('amount_total_signed')):
+ raise UserError("Total Refund dengan Total Journal Harus Sama.")
if rec.status_payment == 'pending':
rec.status_payment = 'done'
rec.refund_date = fields.Date.context_today(self)
@@ -820,15 +1042,27 @@ class RefundSaleOrder(models.Model):
# Ambil label refund type
refund_type_label = dict(
self.fields_get(allfields=['refund_type'])['refund_type']['selection']
- ).get(refund.refund_type, '').replace("Refund ", "").upper()
-
+ ).get(refund.refund_type, '')
+
+ # Normalisasi
+ refund_type_label = refund_type_label.upper()
+
+ if refund.refund_type in ['barang_kosong', 'barang_kosong_sebagian', 'barang_kosong_indent']:
+ refund_type_label = "REFUND BARANG KOSONG"
+ elif refund.refund_type in ['retur_half', 'retur']:
+ refund_type_label = "REFUND RETUR BARANG"
+ elif refund.refund_type == 'uang':
+ refund_type_label = "REFUND LEBIH BAYAR"
+ elif refund.refund_type == 'salah_transfer':
+ refund_type_label = "REFUND SALAH TRANSFER"
if not partner:
raise UserError("❌ Partner tidak ditemukan.")
# Ref format
- ref_text = f"REFUND {refund_type_label} {refund.name or ''} {partner.display_name}".upper()
+ ref_text = f"{refund_type_label} {refund.name or ''} {partner.display_name}".upper()
+ admintex = f"BIAYA ADMIN BANK {refund_type_label} {refund.name or ''} {partner.display_name}".upper()
# Buat Account Move (Journal Entry)
account_move = self.env['account.move'].create({
@@ -839,10 +1073,10 @@ class RefundSaleOrder(models.Model):
'refund_so_ids': [(6, 0, refund.sale_order_ids.ids)],
'partner_id': partner.id,
})
-
+ admintf = refund.biaya_admin
amount = refund.amount_refund
# 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
+ second_account_id = 450 if refund.refund_type not in ['barang_kosong', 'barang_kosong_sebagian', 'barang_kosong_indent'] else 668
debit_line = {
'move_id': account_move.id,
@@ -854,6 +1088,16 @@ class RefundSaleOrder(models.Model):
'name': ref_text,
}
+ adminline = {
+ 'move_id': account_move.id,
+ 'account_id': 555,
+ 'partner_id': partner.id,
+ 'currency_id': 12,
+ 'debit': admintf,
+ 'credit': 0.0,
+ 'name': admintex,
+ }
+
credit_line = {
'move_id': account_move.id,
'account_id': 389, # Intransit BCA
@@ -864,7 +1108,19 @@ class RefundSaleOrder(models.Model):
'name': ref_text,
}
- self.env['account.move.line'].create([debit_line, credit_line])
+ credit_admin_line = {
+ 'move_id': account_move.id,
+ 'account_id': 389, # Intransit BCA
+ 'partner_id': partner.id,
+ 'currency_id': 12,
+ 'debit': 0.0,
+ 'credit': admintf,
+ 'name': admintex,
+ }
+
+ journal_line = [debit_line, credit_line, adminline, credit_admin_line] if admintf > 0 else [debit_line, credit_line]
+
+ self.env['account.move.line'].create(journal_line)
return {
'name': _('Journal Entries'),
@@ -878,7 +1134,8 @@ class RefundSaleOrder(models.Model):
def _compute_journal_refund_move_id(self):
for rec in self:
move = self.env['account.move'].search([
- ('refund_id', '=', rec.id)
+ ('refund_id', '=', rec.id),
+ ('state', '!=', 'cancel')
], limit=1)
rec.journal_refund_move_id = move
@@ -1039,7 +1296,7 @@ class RefundSaleOrder(models.Model):
'origin': ','.join(refund.sale_order_ids.mapped('name')),
'origin_so': refund.sale_order_ids.id,
'operations': picking.id,
- 'return_type': 'revisi_so',
+ 'return_type': 'retur_so',
'invoice_id': [(6, 0, refund.invoice_ids.ids)],
'refund_id': refund.id,
'line_ids': line_vals,