|
@@ -239,30 +239,33 @@ class EiruAccountInterest(models.Model):
|
|
|
descrip = descrip+" Descuento %d" % (line['discount'])
|
|
|
|
|
|
if (accountInterestLine):
|
|
|
- invoice_line.append([0,False, {
|
|
|
- 'name': descrip,
|
|
|
- 'account_id': interestConfig.line_account_id.id,
|
|
|
- 'quantity': 1,
|
|
|
- 'price_unit': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
|
|
|
- 'price_subtotal': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
|
|
|
- 'partner_id': accountInterest.customer_id.id,
|
|
|
- 'invoice_line_tax_id': [(6, 0,[x.id for x in interestConfig.line_tax_id])],
|
|
|
- }])
|
|
|
-
|
|
|
- invoice = {
|
|
|
- 'partner_id': accountInterest.customer_id.id,
|
|
|
- 'currency_id': accountInterest.currency_id.id,
|
|
|
- 'date_invoice': dateServer,
|
|
|
- '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
|
|
|
- }
|
|
|
+ if (accountInterestLine.amount_interest > line['discount']):
|
|
|
+ invoice_line.append([0,False, {
|
|
|
+ 'name': descrip,
|
|
|
+ 'account_id': interestConfig.line_account_id.id,
|
|
|
+ 'quantity': 1,
|
|
|
+ 'price_unit': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
|
|
|
+ 'price_subtotal': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
|
|
|
+ 'partner_id': accountInterest.customer_id.id,
|
|
|
+ 'invoice_line_tax_id': [(6, 0,[x.id for x in interestConfig.line_tax_id])],
|
|
|
+ }])
|
|
|
+
|
|
|
+ accountInvoice=[]
|
|
|
+ if (invoice_line):
|
|
|
+ invoice = {
|
|
|
+ 'partner_id': accountInterest.customer_id.id,
|
|
|
+ 'currency_id': accountInterest.currency_id.id,
|
|
|
+ 'date_invoice': dateServer,
|
|
|
+ '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')
|
|
|
+ ''' 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'])
|
|
@@ -272,12 +275,13 @@ class EiruAccountInterest(models.Model):
|
|
|
moveLine.write({'date_interest': dateServer})
|
|
|
|
|
|
accountInterestLine.write({
|
|
|
- 'invoice': accountInvoice.id,
|
|
|
- 'reference': accountInvoice.number,
|
|
|
- 'state': 'invoiced',
|
|
|
+ 'invoice': accountInvoice.id if (accountInvoice and (line['interes'] > line['discount'])) else '',
|
|
|
+ 'reference': accountInvoice.number if(accountInvoice and (line['interes'] > line['discount'])) else '',
|
|
|
+ 'state': 'invoiced' if (line['interes'] > line['discount']) else 'discount',
|
|
|
'amount_dicount': round(line['discount'],decimal_precision)
|
|
|
})
|
|
|
|
|
|
+
|
|
|
return {
|
|
|
'state': True,
|
|
|
'message': 'Operación exitosa'
|