account_analytic_account.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api, _
  3. from openerp.exceptions import Warning
  4. class AnalyticAccount(models.Model):
  5. _inherit = 'account.analytic.account'
  6. # cuotas
  7. cuota_total = fields.Integer(string="Total de cuotas")
  8. nro_cuotas = fields.Integer(string="Cuota actual")
  9. @api.multi
  10. def recurring_create_invoice(self):
  11. self.nro_cuotas = self.nro_cuotas + 1
  12. if self.nro_cuotas <= self.cuota_total:
  13. value = super(AnalyticAccount, self).recurring_create_invoice()
  14. cuota_string = "Cuota "+ str(self.nro_cuotas)+"/"+str(self.cuota_total)
  15. cuota_tot=self.cuota_total
  16. for each in value:
  17. invoice = self.env['account.invoice'].search([('id','=',each)])
  18. invoice.write({'cuotas': cuota_string})
  19. invoice.write({'cuota_total': cuota_tot})
  20. return value
  21. else:
  22. raise Warning(_("Ya no puede generar cuotas para este contrato."))
  23. @api.model
  24. def recurring_create_invoice_inmobiliaria(self):
  25. value = super(AnalyticAccount, self)._cron_recurring_create_invoice()
  26. for each in value:
  27. invoice = self.env['account.invoice'].search([('id','=',each)])
  28. contract = self.env['account.analytic.account'].search([('code','=',invoice.origin)])
  29. contract.nro_cuotas = contract.nro_cuotas + 1
  30. self.env.cr.execute('update account_analytic_account set nro_cuotas = %s where id = %s', (contract.nro_cuotas, contract.id))
  31. cuota_string = "Cuota "+ str(contract.nro_cuotas)+"/"+str(contract.cuota_total)
  32. self.env.cr.execute('update account_invoice set cuotas = %s where id = %s', (cuota_string, invoice.id))
  33. self.env.cr.execute('update account_invoice set cuota_total = %s where id = %s', (cuota_tot, invoice.id))
  34. return value