diff options
Diffstat (limited to 'fixco_custom/models/invoice_reklas.py')
| -rw-r--r-- | fixco_custom/models/invoice_reklas.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/fixco_custom/models/invoice_reklas.py b/fixco_custom/models/invoice_reklas.py index d97d868..584d357 100644 --- a/fixco_custom/models/invoice_reklas.py +++ b/fixco_custom/models/invoice_reklas.py @@ -73,16 +73,35 @@ class InvoiceReklas(models.TransientModel): # invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) # self.pay_amt = invoices.amount_total + def compare_amount_uangmuka_reklas(self): + if self.reklas_type == 'penjualan': + invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) + if invoices.uangmuka == True: + uangmuka = invoices.amount_total + reklas = self.env['account.move'].search([ + ('sale_id', '=', invoices.sale_id.id), + ('move_type', '=', 'entry'), + ('reklas', '=', True), + ('state', '=', 'posted') + ]) + + reklas_uangmuka = sum(reklas.mapped('amount_total_signed')) or 0 + total_reklas = reklas_uangmuka + self.pay_amt + if total_reklas > uangmuka: + raise UserError('Total reklas tidak boleh melebihi total uang muka') + def create_reklas(self): if not self.reklas_type: raise UserError('Reklas Tipe harus diisi') if not self.reklas_id: raise UserError('Nomor CAB harus diisi') + + self.compare_amount_uangmuka_reklas() invoices = self.env['account.move'].browse(self._context.get('active_ids', [])) current_time = datetime.now() - for invoice in invoices: + for invoice in invoices: # Ambil nama PO jika ada po_name = invoice.purchase_id.name if invoice.purchase_id else '' @@ -99,7 +118,9 @@ class InvoiceReklas(models.TransientModel): parameters_header = { 'ref': ref_name, 'date': current_time, - 'journal_id': 19 + 'journal_id': 19, + 'sale_id': invoice.sale_id.id, + 'reklas': True, } if invoice.purchase_id: @@ -123,7 +144,7 @@ class InvoiceReklas(models.TransientModel): parameter_debit = { 'move_id': account_move.id, 'account_id': 578, # penerimaan belum alokasi - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, @@ -132,7 +153,7 @@ class InvoiceReklas(models.TransientModel): parameter_credit = { 'move_id': account_move.id, 'account_id': 347, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, @@ -142,7 +163,7 @@ class InvoiceReklas(models.TransientModel): parameter_debit = { 'move_id': account_move.id, 'account_id': 388, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': self.pay_amt, 'credit': 0, @@ -151,7 +172,7 @@ class InvoiceReklas(models.TransientModel): parameter_credit = { 'move_id': account_move.id, 'account_id': 579, - 'partner_id': invoice.partner_id.id, + 'partner_id': invoice.line_ids[0].partner_id.id, 'currency_id': 12, 'debit': 0, 'credit': self.pay_amt, |
