|
@@ -59,12 +59,16 @@ class EiruAccountInterest(models.Model):
|
|
|
}for interest in self.env['account.interest'].browse(id)]
|
|
|
|
|
|
'''
|
|
|
- get Account Invoice
|
|
|
+ ____ _ ___ _ _
|
|
|
+ / ___| ___ _ __ ___ _ __ __ _| |_ ___ |_ _|_ __ | |_ ___ _ __ ___ ___| |_
|
|
|
+ | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \ | || '_ \| __/ _ \ '__/ _ \/ __| __|
|
|
|
+ | |_| | __/ | | | __/ | | (_| | || __/ | || | | | || __/ | | __/\__ \ |_
|
|
|
+ \____|\___|_| |_|\___|_| \__,_|\__\___| |___|_| |_|\__\___|_| \___||___/\__|
|
|
|
'''
|
|
|
@api.model
|
|
|
def get_account_invoice_interest(self, invoice=None, partner=None):
|
|
|
_logger.info('Verify invoice')
|
|
|
- domain = [('state', '=', 'open')]
|
|
|
+ domain = [('state', '=', 'open'),('is_interest', '=', False)]
|
|
|
|
|
|
if (invoice):
|
|
|
domain.append(('id', '=', invoice))
|
|
@@ -75,6 +79,8 @@ class EiruAccountInterest(models.Model):
|
|
|
for invoice in accountInvoice:
|
|
|
self.get_move_line_in_invoice(invoice.id)
|
|
|
|
|
|
+ return True
|
|
|
+
|
|
|
'''
|
|
|
Get move Line.
|
|
|
'''
|
|
@@ -87,14 +93,23 @@ class EiruAccountInterest(models.Model):
|
|
|
domain = [('state','!=','draft'), ('credit','<=', 0), ('partner_id','=',accountInvoice.partner_id.id),('invoice','=',accountInvoice.id)]
|
|
|
for line in self.env['account.move.line'].search(domain):
|
|
|
expiredDays = dateServer - self._convert_str_to_datetime(line.date_maturity)
|
|
|
+ if (line.date_interest):
|
|
|
+ expiredDays = dateServer - self._convert_str_to_datetime(line.date_interest)
|
|
|
+
|
|
|
if ((line.amount_residual <= 0) or (expiredDays.days <= 0)):
|
|
|
continue
|
|
|
|
|
|
''' verify account.interest '''
|
|
|
accountInterest = self.eiru_create_account_interest(accountInvoice.id)
|
|
|
+ if (not accountInterest):
|
|
|
+ return {'state': False}
|
|
|
|
|
|
''' verify account.interest.line '''
|
|
|
interrstLine = self.eiru_create_account_interest_lines(accountInvoice.id, accountInterest.id, line.id, expiredDays.days)
|
|
|
+ if (not interrstLine):
|
|
|
+ return {'state': False}
|
|
|
+
|
|
|
+ return True
|
|
|
|
|
|
'''
|
|
|
Create Account Interest
|
|
@@ -129,7 +144,8 @@ class EiruAccountInterest(models.Model):
|
|
|
accountInterest = self.env['account.interest'].browse(interestID)
|
|
|
moveLine = self.env['account.move.line'].browse(moveId)
|
|
|
interestConfig = self.env['account.interest.config'].search([('active', '=', True)])
|
|
|
- interestLine = self.env['account.interest.line'].search([('interest_id.id', '=', accountInterest.id),('move_line_id.id', '=',moveLine.id)])
|
|
|
+ domain = [('interest_id.id', '=', accountInterest.id),('move_line_id.id', '=',moveLine.id),('state', '=', 'open')]
|
|
|
+ interestLine = self.env['account.interest.line'].search(domain)
|
|
|
|
|
|
decimalPlaces = accountInvoice.currency_id.decimal_places
|
|
|
if (not decimalPlaces):
|
|
@@ -145,7 +161,7 @@ class EiruAccountInterest(models.Model):
|
|
|
'expired_days': expiredDays,
|
|
|
'amount_residual': round(amount_residual,decimalPlaces),
|
|
|
'amount_interest': round((expiredDays * (amount_residual * (interestConfig.interest_rate / 100))),decimalPlaces),
|
|
|
- 'interest_id': accountInterest.id
|
|
|
+ 'interest_id': accountInterest.id,
|
|
|
}
|
|
|
|
|
|
if (not interestLine):
|
|
@@ -203,13 +219,22 @@ class EiruAccountInterest(models.Model):
|
|
|
'journal_id': interestConfig.invoice_journal_id.id,
|
|
|
'account_id': interestConfig.invoice_account_id.id,
|
|
|
'invoice_line': invoice_line,
|
|
|
+ 'origin': '%s/%s' % (accountInterest.name, accountInterest.reference),
|
|
|
+ 'is_interest': True
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ ''' Create / open /invoice '''
|
|
|
accountInvoice = self.env['account.invoice'].create(invoice)
|
|
|
accountInvoice.signal_workflow('invoice_open')
|
|
|
+
|
|
|
for line in interestLine:
|
|
|
accountInterestLine = self.env['account.interest.line'].browse(line['id'])
|
|
|
if (accountInterestLine):
|
|
|
+ moveLine = self.env['account.move.line'].browse(accountInterestLine.move_line_id.id)
|
|
|
+ if (moveLine):
|
|
|
+ moveLine.write({'date_interest': dateServer})
|
|
|
+
|
|
|
accountInterestLine.write({
|
|
|
'invoice': accountInvoice.id,
|
|
|
'reference': accountInvoice.number,
|