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 invoice in invoices: ref_name = 'REKLAS ' + invoice.reklas_id.name + " UANG MUKA PENJUALAN " + invoice.name + " " + invoice.partner_id.name parameters_header = { 'ref': ref_name, 'date': current_time, 'journal_id': 13 } account_move = self.env['account.move'].create([parameters_header]) _logger.info('Success Reklas with %s' % account_move.name) parameter_debit = { 'move_id': account_move.id, 'account_id': 668, # uang muka penjualan 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': invoice.pay_amt, 'credit': 0, 'name': ref_name } parameter_credit = { 'move_id': account_move.id, 'account_id': 395, 'partner_id': invoice.partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': invoice.pay_amt, 'name': ref_name } self.env['account.move.line'].create([parameter_debit, parameter_credit]) account_move_ids.append(account_move.id) invoice.unlink() self.unlink() 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')