|
@@ -8,6 +8,39 @@ from datetime import datetime,timedelta
|
|
|
import logging
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
+class ResPartnerInterest(models.Model):
|
|
|
+ _inherit = 'res.partner'
|
|
|
+
|
|
|
+ @api.model
|
|
|
+ def eiru_account_interest_verify_partner(self, id):
|
|
|
+ partner = self.env['res.partner'].browse(id)
|
|
|
+ partnerIDS = []
|
|
|
+
|
|
|
+ if (partner.is_company):
|
|
|
+ partnerIDS= map(lambda x: x.id, partner.child_ids)
|
|
|
+
|
|
|
+ partnerIDS.append(partner.id)
|
|
|
+
|
|
|
+ interest = self. env['account.interest']
|
|
|
+ interest.get_account_invoice_interest(None,partnerIDS)
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'state': True,
|
|
|
+ 'message': "Verificación de interés terminado",
|
|
|
+ }
|
|
|
+
|
|
|
+class AccountInvoiceInterest(models.Model):
|
|
|
+ _inherit = 'account.invoice'
|
|
|
+
|
|
|
+ @api.model
|
|
|
+ def eiru_account_interest_verify_invoice(self, id):
|
|
|
+ interest = self. env['account.interest']
|
|
|
+ interest.get_account_invoice_interest(id,None)
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'state': True,
|
|
|
+ 'message': "Verificación de interés terminado",
|
|
|
+ }
|
|
|
|
|
|
class EiruAccountInterest(models.Model):
|
|
|
_inherit = 'account.interest'
|
|
@@ -73,9 +106,10 @@ class EiruAccountInterest(models.Model):
|
|
|
if (invoice):
|
|
|
domain.append(('id', '=', invoice))
|
|
|
if (partner):
|
|
|
- domain.append(('partner_id.id', '=', partner))
|
|
|
+ domain.append(('partner_id.id', 'in', partner))
|
|
|
|
|
|
accountInvoice = self.env['account.invoice'].search(domain)
|
|
|
+
|
|
|
for invoice in accountInvoice:
|
|
|
self.get_move_line_in_invoice(invoice.id)
|
|
|
|
|
@@ -90,7 +124,7 @@ class EiruAccountInterest(models.Model):
|
|
|
|
|
|
dateServer = self._convert_str_to_datetime(self.get_date())
|
|
|
|
|
|
- domain = [('state','!=','draft'), ('credit','<=', 0), ('partner_id','=',accountInvoice.partner_id.id),('invoice','=',accountInvoice.id)]
|
|
|
+ domain = [('state','!=','draft'), ('credit','<=', 0),('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):
|
|
@@ -118,7 +152,7 @@ class EiruAccountInterest(models.Model):
|
|
|
_logger.info('Verify account interest')
|
|
|
accountInvoice = self.env['account.invoice'].browse(invoiceId)
|
|
|
|
|
|
- domain = [('invoice_id', '=', accountInvoice.id),('customer_id.id', '=', accountInvoice.partner_id.id)]
|
|
|
+ domain = [('invoice_id', '=', accountInvoice.id)]
|
|
|
accountInterest = self.env['account.interest'].search(domain)
|
|
|
|
|
|
dateServer = self.get_date()
|
|
@@ -126,7 +160,7 @@ class EiruAccountInterest(models.Model):
|
|
|
if (not accountInterest):
|
|
|
accountInterest = self.env['account.interest'].create({
|
|
|
'invoice_id': accountInvoice.id,
|
|
|
- 'customer_id': accountInvoice.partner_id.id,
|
|
|
+ 'customer_id': accountInvoice.commercial_partner_id.id if(accountInvoice.commercial_partner_id) else accountInvoice.partner_id.id,
|
|
|
'date': dateServer,
|
|
|
'currency_id': accountInvoice.currency_id.id,
|
|
|
'reference': accountInvoice.number,
|
|
@@ -221,7 +255,6 @@ class EiruAccountInterest(models.Model):
|
|
|
'invoice_line': invoice_line,
|
|
|
'origin': '%s/%s' % (accountInterest.name, accountInterest.reference),
|
|
|
'is_interest': True
|
|
|
-
|
|
|
}
|
|
|
|
|
|
''' Create / open /invoice '''
|
|
@@ -238,7 +271,8 @@ class EiruAccountInterest(models.Model):
|
|
|
accountInterestLine.write({
|
|
|
'invoice': accountInvoice.id,
|
|
|
'reference': accountInvoice.number,
|
|
|
- 'state': 'invoiced'
|
|
|
+ 'state': 'invoiced',
|
|
|
+ 'amount_dicount': round(line['discount'],decimal_precision)
|
|
|
})
|
|
|
|
|
|
return {
|