12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, api
- from openerp.osv import osv
- class invoice_interes(models.Model):
- _inherit = "account.invoice"
- _name = "account.invoice"
- move_line_debt = fields.One2many('account.move.line', inverse_name="invoice", string="id Move line", domain=['&', ('reconcile_id', '=', False), '&', ('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
- state_move_line= fields.Boolean(readonly=True, default=False)
- @api.multi
- def update_ammount_move(self):
- # Variables
- total_voucher=0
- monto_residual=0
- cuota_dividida=0
- estado =None
- cambio_py=0
- if len(self.payment_ids) < 1:
- raise osv.except_osv('Advertencia','No es posible continuar con la operación, para generar la división del saldo es necesario que pague su primera entrega')
- return
- #Verifica si existe mas de una linea en move live
- if len(self.move_line_debt) > 1:
- # Actulizar estado del journal cuando tipo es venta
- datos_journal = self.env['account.journal'].search([('type', '=', 'sale')])
- datos_journal.write({'entry_posted' : True})
- # rate_model = self.env['res.currency.rate'].search([('currency_id', '=', 166)])
- # rate_py = rate_model[len(rate_model)-1]
- # cambio_py =rate_py.rate
- if self.currency_id.id == 3:
- monto_residual = self.residual
- else:
- monto_residual = self.residual/self.currency_id.rate_ids.rate
- # Calular la divicion la cuota
- cuota_dividida = (monto_residual / len(self.move_line_debt))
- print(monto_residual)
- print(cuota_dividida)
- for move_line in self.move_line_debt:
- move_dato = self.env['account.move'].search([('id', 'in', move_line.move_id.ids)])
- if move_dato:
- estado = move_dato.state
- move_dato.write({'state' : 'draft'})
- line_voucher = self.env['account.voucher.line'].search([('move_line_id', '=', move_line.id), ('amount', '>', 0)],order='id')
- print(line_voucher)
- if line_voucher:
- for voucher in line_voucher:
- if voucher.voucher_id.payment_rate_currency_id.id == 3:
- print("moneda Dolar ")
- total_voucher += voucher.amount
- else:
- print("ota moneda")
- print("Cambio "+str(voucher.voucher_id.payment_rate_currency_id))
- total_voucher +=(voucher.amount / voucher.voucher_id.payment_rate_currency_id.rate_ids.rate)
- print("cuota "+str(cuota_dividida))
- print("pagado " +str(total_voucher))
- print('total '+str(cuota_dividida + total_voucher))
- move_line_dato = self.env['account.move.line'].search([('id', '=', move_line.id)])
- move_line_dato.write({'debit' : (cuota_dividida + total_voucher)})
- # move_line_dato.write({'amount_currency' : ((move_line_dato.debit - move_line_dato.credit)*cambio_py)})
- if estado == None:
- estado='draft'
- move_dato.write({'state' : estado})
- # move_line_dato._amount_residual(move_line_dato.amount_residual_currency)
- datos_journal.write({'entry_posted' : False})
- incoice_datos = self.env['account.invoice'].search([('id', '=',self.id )])
- incoice_datos.write({'state_move_line' : True})
- move_line_state = self.env['account.move.line'].search([('ref', '=', self.number)])
- move_line_state.write({'state' : 'valid'})
- else:
- raise osv.except_osv('Advertencia','No es posible generar la división del saldo sobre una única linea')
- return
|