summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/invoice_reklas_penjualan.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/invoice_reklas_penjualan.py')
-rw-r--r--indoteknik_custom/models/invoice_reklas_penjualan.py60
1 files changed, 44 insertions, 16 deletions
diff --git a/indoteknik_custom/models/invoice_reklas_penjualan.py b/indoteknik_custom/models/invoice_reklas_penjualan.py
index 80c3ed43..2f5ee160 100644
--- a/indoteknik_custom/models/invoice_reklas_penjualan.py
+++ b/indoteknik_custom/models/invoice_reklas_penjualan.py
@@ -17,43 +17,70 @@ class InvoiceReklasPenjualan(models.TransientModel):
def create_reklas_penjualan(self):
invoices = self.invoice_reklas_line
-
current_time = datetime.now()
account_move_ids = []
- for invoice in invoices:
- ref_name = 'REKLAS ' + invoice.reklas_id.name + " UANG MUKA PENJUALAN " + invoice.name + " " + invoice.partner_id.name
+
+ for line in invoices:
+ # Ambil nama SO jika ada
+ so_name = line.sale_id.name if line.sale_id else ''
+
+ # Susun referensi nama jurnal
+ ref_name = 'REKLAS {} UANG MUKA PENJUALAN {}{} {}'.format(
+ line.reklas_id.name or '',
+ line.name or '',
+ f" - {so_name}" if so_name else '',
+ line.partner_id.name or ''
+ )
+
+ # Header jurnal
parameters_header = {
'ref': ref_name,
'date': current_time,
- 'journal_id': 13
+ 'journal_id': 13,
+ # ⬇️ Tambahkan jika tahu invoice asal (name = ID Bill)
+ 'bill_id': int(line.name) if line.name and line.name.isdigit() else False,
}
account_move = self.env['account.move'].create([parameters_header])
_logger.info('Success Reklas with %s' % account_move.name)
- parameter_debit = {
+ # Simpan info asal (optional)
+ account_move.invoice_origin = line.name
+
+ # Simpan juga ke `reklas_misc_id` jika ditemukan invoice valid
+ if line.name and line.name.isdigit():
+ invoice_id = self.env['account.move'].browse(int(line.name))
+ if invoice_id.exists():
+ invoice_id.reklas_misc_id = account_move.id
+
+ # Buat debit kredit line
+ debit_line = {
'move_id': account_move.id,
- 'account_id': 668, # uang muka penjualan
- 'partner_id': invoice.partner_id.id,
+ 'account_id': 668, # akun penerimaan belum alokasi
+ 'partner_id': line.partner_id.id,
'currency_id': 12,
- 'debit': invoice.pay_amt,
+ 'debit': line.pay_amt,
'credit': 0,
'name': ref_name
}
- parameter_credit = {
+ credit_line = {
'move_id': account_move.id,
- 'account_id': 395,
- 'partner_id': invoice.partner_id.id,
+ 'account_id': 395, # akun pengurang
+ 'partner_id': line.partner_id.id,
'currency_id': 12,
'debit': 0,
- 'credit': invoice.pay_amt,
+ 'credit': line.pay_amt,
'name': ref_name
}
- self.env['account.move.line'].create([parameter_debit, parameter_credit])
+
+ self.env['account.move.line'].create([debit_line, credit_line])
account_move_ids.append(account_move.id)
- invoice.unlink()
-
- self.unlink()
+
+ line.unlink() # bersihkan line setelah selesai
+
+ self.unlink() # hapus wizard utama setelah selesai
+
+ # Tampilkan hasil jurnal reklas
return {
'name': _('Journal Entries'),
'view_mode': 'tree,form',
@@ -63,6 +90,7 @@ class InvoiceReklasPenjualan(models.TransientModel):
'domain': [('id', 'in', account_move_ids)],
}
+
class InvoiceReklasPenjualanLine(models.TransientModel):
_name = 'invoice.reklas.penjualan.line'
_description = "digunakan untuk reklas Uang Muka Penjualan"