from odoo import api, fields, models, _ from odoo.exceptions import UserError from datetime import datetime from odoo.http import request import logging _logger = logging.getLogger(__name__) class InvoiceReklasPenjualan(models.TransientModel): _name = 'invoice.reklas.penjualan' _description = "digunakan untuk reklas Uang Muka Penjualan" name = fields.Char(string='Name') invoice_reklas_line = fields.One2many('invoice.reklas.penjualan.line', 'invoice_reklas_id', string='Invoice Reklas Line') def create_reklas_penjualan(self): invoices = self.invoice_reklas_line current_time = datetime.now() account_move_ids = [] 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, # ⬇️ 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) # 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, # akun penerimaan belum alokasi 'partner_id': line.partner_id.id, 'currency_id': 12, 'debit': line.pay_amt, 'credit': 0, 'name': ref_name } credit_line = { 'move_id': account_move.id, 'account_id': 395, # akun pengurang 'partner_id': line.partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': line.pay_amt, 'name': ref_name } self.env['account.move.line'].create([debit_line, credit_line]) account_move_ids.append(account_move.id) 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', 'res_model': 'account.move', 'target': 'current', 'type': 'ir.actions.act_window', 'domain': [('id', 'in', account_move_ids)], } class InvoiceReklasPenjualanLine(models.TransientModel): _name = 'invoice.reklas.penjualan.line' _description = "digunakan untuk reklas Uang Muka Penjualan" invoice_reklas_id = fields.Many2one('invoice.reklas.penjualan', string='Invoice Reklas') pay_amt = fields.Float(string='Yang dibayarkan') reklas_id = fields.Many2one('account.move', string='Nomor CAB', domain="[('sale_id', '=', sale_id)]") sale_id = fields.Many2one('sale.order', string='Sale Order') amount_untaxed_signed = fields.Float(string='Tax excluded') amount_total_signed = fields.Float(string='Total') name = fields.Char(string='Name') partner_id = fields.Many2one('res.partner', string='Partner')