account_invoice_move_line.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from openerp.osv import osv
  4. class invoice_interes(models.Model):
  5. _inherit = "account.invoice"
  6. _name = "account.invoice"
  7. 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')])
  8. state_move_line= fields.Boolean(readonly=True, default=False)
  9. @api.multi
  10. def update_ammount_move(self):
  11. # Variables
  12. total_voucher=0
  13. monto_residual=0
  14. cuota_dividida=0
  15. estado =None
  16. cambio_py=0
  17. if len(self.payment_ids) < 1:
  18. 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')
  19. return
  20. #Verifica si existe mas de una linea en move live
  21. if len(self.move_line_debt) > 1:
  22. # Actulizar estado del journal cuando tipo es venta
  23. datos_journal = self.env['account.journal'].search([('type', '=', 'sale')])
  24. datos_journal.write({'entry_posted' : True})
  25. # rate_model = self.env['res.currency.rate'].search([('currency_id', '=', 166)])
  26. # rate_py = rate_model[len(rate_model)-1]
  27. # cambio_py =rate_py.rate
  28. if self.currency_id.id == 3:
  29. monto_residual = self.residual
  30. else:
  31. monto_residual = self.residual/self.currency_id.rate_ids.rate
  32. # Calular la divicion la cuota
  33. cuota_dividida = (monto_residual / len(self.move_line_debt))
  34. print(monto_residual)
  35. print(cuota_dividida)
  36. for move_line in self.move_line_debt:
  37. move_dato = self.env['account.move'].search([('id', 'in', move_line.move_id.ids)])
  38. if move_dato:
  39. estado = move_dato.state
  40. move_dato.write({'state' : 'draft'})
  41. line_voucher = self.env['account.voucher.line'].search([('move_line_id', '=', move_line.id), ('amount', '>', 0)],order='id')
  42. print(line_voucher)
  43. if line_voucher:
  44. for voucher in line_voucher:
  45. if voucher.voucher_id.payment_rate_currency_id.id == 3:
  46. print("moneda Dolar ")
  47. total_voucher += voucher.amount
  48. else:
  49. print("ota moneda")
  50. print("Cambio "+str(voucher.voucher_id.payment_rate_currency_id))
  51. total_voucher +=(voucher.amount / voucher.voucher_id.payment_rate_currency_id.rate_ids.rate)
  52. print("cuota "+str(cuota_dividida))
  53. print("pagado " +str(total_voucher))
  54. print('total '+str(cuota_dividida + total_voucher))
  55. move_line_dato = self.env['account.move.line'].search([('id', '=', move_line.id)])
  56. move_line_dato.write({'debit' : (cuota_dividida + total_voucher)})
  57. # move_line_dato.write({'amount_currency' : ((move_line_dato.debit - move_line_dato.credit)*cambio_py)})
  58. if estado == None:
  59. estado='draft'
  60. move_dato.write({'state' : estado})
  61. # move_line_dato._amount_residual(move_line_dato.amount_residual_currency)
  62. datos_journal.write({'entry_posted' : False})
  63. incoice_datos = self.env['account.invoice'].search([('id', '=',self.id )])
  64. incoice_datos.write({'state_move_line' : True})
  65. move_line_state = self.env['account.move.line'].search([('ref', '=', self.number)])
  66. move_line_state.write({'state' : 'valid'})
  67. else:
  68. raise osv.except_osv('Advertencia','No es posible generar la división del saldo sobre una única linea')
  69. return