|
@@ -4,13 +4,16 @@ import openerp.addons.decimal_precision as dp
|
|
|
from datetime import datetime
|
|
|
from openerp.exceptions import ValidationError
|
|
|
|
|
|
+import logging
|
|
|
+_logger = logging.getLogger(__name__)
|
|
|
+
|
|
|
class AccountInterest(models.Model):
|
|
|
_name = 'account.interest'
|
|
|
|
|
|
name = fields.Char()
|
|
|
date = fields.Date('Date', help="Fecha de operación")
|
|
|
- state = fields.Selection([('cancel', 'Cancelado'),('open', 'Abierto'),('paid', 'Pagado')],'Estado del pago', default="open", help="Estado")
|
|
|
comment = fields.Text('Comment', help="Información adicional")
|
|
|
+ state = fields.Selection([('lines_paid', 'Sin interés'),('lines_open', 'Interés a cobrar.'),('paid', 'Factura pagada')],'Estado del pago', default="lines_open", help="Estado")
|
|
|
## Cliente
|
|
|
customer_id = fields.Many2one('res.partner', string="customer")
|
|
|
## factura
|
|
@@ -63,7 +66,6 @@ class accountInvoiceInterest(models.Model):
|
|
|
is_interest = fields.Boolean('Factura de interés', default=False, help="Indica si esta factura fue generado por un interés.")
|
|
|
interest_line_ids = fields.One2many('account.interest.line', 'invoice', string=' Account Interest Line')
|
|
|
|
|
|
-
|
|
|
''' Unlink Invoice '''
|
|
|
@api.multi
|
|
|
def unlink(self):
|
|
@@ -84,31 +86,88 @@ class accountInvoiceInterest(models.Model):
|
|
|
@api.multi
|
|
|
def write(self, vals):
|
|
|
invoice = super(accountInvoiceInterest, self).write(vals)
|
|
|
+ ''' Cambiar estado de lineas de interés'''
|
|
|
+ interestLinesIDS = self._change_state_account_interest_line(self)
|
|
|
+ ''' Cambiar estado del interés '''
|
|
|
+ interest= self._change_state_account_interest(self)
|
|
|
+
|
|
|
+ return invoice
|
|
|
+
|
|
|
+ ''' Cambiar estado de lineas de interés '''
|
|
|
+ def _change_state_account_interest_line(self, invoice):
|
|
|
+ _logger.info('Change state account.interest.line.')
|
|
|
+ linesIds = []
|
|
|
+ if (invoice.interest_line_ids):
|
|
|
+ linesIds = map(lambda x: x.id, invoice.interest_line_ids)
|
|
|
+
|
|
|
+ if (invoice.interest_ids):
|
|
|
+ linesIds = map(lambda x: x.id, invoice.interest_ids.lines_ids)
|
|
|
|
|
|
- linesIds = map(lambda x: x.id, self.interest_line_ids)
|
|
|
if (linesIds):
|
|
|
interestLine = self.env['account.interest.line'].search([('id', 'in', linesIds)])
|
|
|
+ state = []
|
|
|
|
|
|
- if (interestLine):
|
|
|
- state = []
|
|
|
- if (self.state == 'open'):
|
|
|
+ for line in interestLine:
|
|
|
+ lineInvoice = self.env['account.invoice'].browse(line.invoice.id)
|
|
|
+ if (not lineInvoice):
|
|
|
+ state = {'state': 'open'}
|
|
|
+
|
|
|
+ if (lineInvoice.state == 'open'):
|
|
|
state = {'state': 'invoiced'}
|
|
|
|
|
|
- if (self.state == 'cancel'):
|
|
|
+ if (lineInvoice.state == 'cancel'):
|
|
|
state = {'state': 'invoice_cancel'}
|
|
|
|
|
|
- if (self.state == 'draft'):
|
|
|
+ if (lineInvoice.state == 'draft'):
|
|
|
state = {'state': 'invoice_draft'}
|
|
|
|
|
|
- if (self.state == 'paid'):
|
|
|
+ if (lineInvoice.state == 'paid'):
|
|
|
state = {'state': 'paid'}
|
|
|
|
|
|
if (state):
|
|
|
- for line in interestLine:
|
|
|
- line.write(state)
|
|
|
+ line.write(state)
|
|
|
+ return True
|
|
|
+
|
|
|
+ ''' Cambiar el Estado del account.interest '''
|
|
|
+ def _change_state_account_interest(self, invoice):
|
|
|
+ _logger.info('Change state account.interest')
|
|
|
+ interestIds = []
|
|
|
+ state = []
|
|
|
+
|
|
|
+ if (invoice.interest_line_ids):
|
|
|
+ interestIds = map(lambda x: x.interest_id.id, invoice.interest_line_ids)
|
|
|
+
|
|
|
+ if (invoice.interest_ids):
|
|
|
+ interestIds = map(lambda x: x.id, invoice.interest_ids)
|
|
|
+
|
|
|
+ if (interestIds):
|
|
|
+ accountInterest = self.env['account.interest'].search([('id', 'in', interestIds)])
|
|
|
+ if (accountInterest.lines_ids):
|
|
|
+ linesState = map(lambda x: x.state, accountInterest.lines_ids)
|
|
|
+
|
|
|
+ if (('discount'in linesState) or ('paid' in linesState)):
|
|
|
+ state ={ 'state': 'lines_paid'}
|
|
|
+
|
|
|
+ if ((accountInterest.invoice_id.id == invoice.id) and (invoice.state == 'paid')):
|
|
|
+ state ={ 'state': 'paid'}
|
|
|
+
|
|
|
+ if (('invoiced' in linesState) or ('invoice_cancel' in linesState) or ('invoice_draft' in linesState) or ('open' in linesState)):
|
|
|
+ state ={'state': 'lines_open'}
|
|
|
+
|
|
|
+ if (state):
|
|
|
+ accountInterest.write(state)
|
|
|
|
|
|
return True
|
|
|
|
|
|
+ ''' Verify Status Invoice and interest '''
|
|
|
+ @api.model
|
|
|
+ def eiru_invoice_verify_status(self):
|
|
|
+ invoices = self.env['account.invoice'].search([('type', '=', 'out_invoice')])
|
|
|
+ for invoice in invoices:
|
|
|
+ interestLine = self._change_state_account_interest_line(invoice)
|
|
|
+ interest = self._change_state_account_interest(invoice)
|
|
|
+
|
|
|
+ return True
|
|
|
|
|
|
''' Partner '''
|
|
|
class ResPartnerInterest(models.Model):
|
|
@@ -137,7 +196,6 @@ class AccountInterestLine(models.Model):
|
|
|
('paid', 'Pagado')],'Estado del pago de la linea ', default="open")
|
|
|
amount_dicount = fields.Float('amount disconut', digits_compute=dp.get_precision('Account'), help="Monto del descuento")
|
|
|
|
|
|
-
|
|
|
'''
|
|
|
Move Line
|
|
|
'''
|