|  | @@ -0,0 +1,38 @@
 | 
											
												
													
														|  | 
 |  | +# -*- coding: utf-8 -*-
 | 
											
												
													
														|  | 
 |  | +from openerp import models, fields, api, _
 | 
											
												
													
														|  | 
 |  | +from openerp.exceptions import Warning
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +class AnalyticAccount(models.Model):
 | 
											
												
													
														|  | 
 |  | +    _inherit = 'account.analytic.account'
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    # cuotas
 | 
											
												
													
														|  | 
 |  | +    cuota_total = fields.Integer(string="Total de cuotas")
 | 
											
												
													
														|  | 
 |  | +    nro_cuotas = fields.Integer(string="Cuota actual")
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @api.multi
 | 
											
												
													
														|  | 
 |  | +    def recurring_create_invoice(self):
 | 
											
												
													
														|  | 
 |  | +        self.nro_cuotas = self.nro_cuotas + 1
 | 
											
												
													
														|  | 
 |  | +        if self.nro_cuotas <= self.cuota_total:
 | 
											
												
													
														|  | 
 |  | +            value = super(AnalyticAccount, self).recurring_create_invoice()
 | 
											
												
													
														|  | 
 |  | +            cuota_string = "Cuota "+ str(self.nro_cuotas)+"/"+str(self.cuota_total)
 | 
											
												
													
														|  | 
 |  | +            cuota_tot=self.cuota_total
 | 
											
												
													
														|  | 
 |  | +            for each in value:
 | 
											
												
													
														|  | 
 |  | +                invoice = self.env['account.invoice'].search([('id','=',each)])
 | 
											
												
													
														|  | 
 |  | +                invoice.write({'cuotas': cuota_string})
 | 
											
												
													
														|  | 
 |  | +                invoice.write({'cuota_total': cuota_tot})
 | 
											
												
													
														|  | 
 |  | +            return value
 | 
											
												
													
														|  | 
 |  | +        else:
 | 
											
												
													
														|  | 
 |  | +            raise Warning(_("Ya no puede generar cuotas para este contrato."))
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    @api.model
 | 
											
												
													
														|  | 
 |  | +    def recurring_create_invoice_inmobiliaria(self):
 | 
											
												
													
														|  | 
 |  | +        value = super(AnalyticAccount, self)._cron_recurring_create_invoice()
 | 
											
												
													
														|  | 
 |  | +        for each in value:
 | 
											
												
													
														|  | 
 |  | +            invoice = self.env['account.invoice'].search([('id','=',each)])
 | 
											
												
													
														|  | 
 |  | +            contract = self.env['account.analytic.account'].search([('code','=',invoice.origin)])
 | 
											
												
													
														|  | 
 |  | +            contract.nro_cuotas = contract.nro_cuotas + 1
 | 
											
												
													
														|  | 
 |  | +            self.env.cr.execute('update account_analytic_account set nro_cuotas = %s where id = %s', (contract.nro_cuotas, contract.id))
 | 
											
												
													
														|  | 
 |  | +            cuota_string = "Cuota "+ str(contract.nro_cuotas)+"/"+str(contract.cuota_total)
 | 
											
												
													
														|  | 
 |  | +            self.env.cr.execute('update account_invoice set cuotas = %s where  id = %s', (cuota_string, invoice.id))
 | 
											
												
													
														|  | 
 |  | +            self.env.cr.execute('update account_invoice set cuota_total = %s where  id = %s', (cuota_tot, invoice.id))
 | 
											
												
													
														|  | 
 |  | +        return value
 |