123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- # For copyright and license notices, see __openerp__.py file in module root
- # directory
- ##############################################################################
- from dateutil.relativedelta import relativedelta
- from datetime import datetime
- import logging
- import time
- from openerp import models, fields, api
- from openerp.addons.decimal_precision import decimal_precision as dp
- class account_analytic_account(models.Model):
- _inherit = "account.analytic.account"
- recurring_date_due = fields.Date("Fecha de vencimiento")
- recurring_day = fields.Char("Día Vencimiento")
- recurring_total_amount = fields.Float(
- 'Monto',
- compute='_compute_recurring_total_amount',
- # we dont make storable so it is compatible with contract
- # discount
- # store=True,
- digits=dp.get_precision('Account'),
- )
- _defaults = {
- 'recurring_date_due': lambda *a: time.strftime('%Y-%m-%d')
- }
- @api.one
- @api.depends(
- 'recurring_invoice_line_ids.quantity',
- 'recurring_invoice_line_ids.price_unit',
- )
- def _compute_recurring_total_amount(self):
- self.recurring_total_amount = sum(
- self.recurring_invoice_line_ids.mapped('price_subtotal'))
- @api.multi
- def recurring_create_invoice(self):
- current_date = time.strftime('%Y-%m-%d')
- if(self.recurring_date_due, '<=', current_date):
- value = super(account_analytic_account, self).recurring_create_invoice()
- date_due=self.recurring_date_due
- for each in value:
- invoice = self.env['account.invoice'].search([('id','=',each)])
- invoice.write({'date_due': date_due})
- self.recurring_date_due = (datetime.strptime(self.recurring_date_due,'%Y-%m-%d') + relativedelta(months=1)).strftime('%Y-%m-%d')
- return value
- else:
- raise Warning(_("Ya no puede generar cuotas para este contrato."))
- @api.model
- def recurring_create_invoice_giganet(self):
- value = super(account_analytic_account, 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.recurring_date_due = (datetime.strptime(self.recurring_date_due,'%Y-%m-%d') + relativedelta(months=1)).strftime('%Y-%m-%d')
- self.env.cr.execute('update account_analytic_account set recurring_date_due = %s where id = %s', (contract.recurring_date_due, contract.id))
- self.env.cr.execute('update account_invoice set date_due = %s where id = %s', (date_due, invoice.id))
- return value
|