diff --git a/account_loan/__manifest__.py b/account_loan/__manifest__.py
index c5ffbcca..7ff8b175 100644
--- a/account_loan/__manifest__.py
+++ b/account_loan/__manifest__.py
@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Loan management",
- "version": "11.0.1.0.0",
+ "version": "11.0.1.1.0",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "http://github.com/OCA/account-financial-tools",
"license": "AGPL-3",
diff --git a/account_loan/model/account_loan.py b/account_loan/model/account_loan.py
index dfa3aad6..74550e9c 100644
--- a/account_loan/model/account_loan.py
+++ b/account_loan/model/account_loan.py
@@ -241,6 +241,10 @@ class AccountLoan(models.Model):
string='Total interests payed',
compute='_compute_total_amounts',
)
+ post_invoice = fields.Boolean(
+ default=True,
+ help='Invoices will be posted automatically'
+ )
_sql_constraints = [
('name_uniq', 'unique(name, company_id)',
diff --git a/account_loan/model/account_loan_line.py b/account_loan/model/account_loan_line.py
index 169c8d3a..50099e3c 100644
--- a/account_loan/model/account_loan_line.py
+++ b/account_loan/model/account_loan_line.py
@@ -328,6 +328,8 @@ class AccountLoanLine(models.Model):
for line in invoice.invoice_line_ids:
line._set_taxes()
invoice.compute_taxes()
+ if record.loan_id.post_invoice:
+ invoice.action_invoice_open()
return res
@api.multi
diff --git a/account_loan/tests/test_loan.py b/account_loan/tests/test_loan.py
index 40b1bc08..dba80094 100644
--- a/account_loan/tests/test_loan.py
+++ b/account_loan/tests/test_loan.py
@@ -223,6 +223,7 @@ class TestLoan(TransactionCase):
self.partner.property_account_payable_id = self.payable_account
self.assertEqual(loan.journal_type, 'general')
loan.is_leasing = True
+ loan.post_invoice = False
self.assertEqual(loan.journal_type, 'purchase')
loan.long_term_loan_account_id = self.lt_loan_account
loan.rate_type = 'real'
@@ -243,8 +244,6 @@ class TestLoan(TransactionCase):
}).run()
self.assertTrue(line.has_invoices)
self.assertFalse(line.has_moves)
- self.assertTrue(line.invoice_ids)
- self.assertFalse(line.move_ids)
self.assertIn(line.invoice_ids.id, action['domain'][0][2])
with self.assertRaises(UserError):
self.env['account.loan.pay.amount'].create({
@@ -299,6 +298,34 @@ class TestLoan(TransactionCase):
with self.assertRaises(UserError):
line.view_process_values()
+ def test_fixed_principal_loan_auto_post(self):
+ amount = 24000
+ periods = 24
+ loan = self.create_loan('fixed-principal', amount, 1, periods)
+ self.partner.property_account_payable_id = self.payable_account
+ self.assertEqual(loan.journal_type, 'general')
+ loan.is_leasing = True
+ self.assertEqual(loan.journal_type, 'purchase')
+ loan.long_term_loan_account_id = self.lt_loan_account
+ loan.rate_type = 'real'
+ loan.compute_lines()
+ self.assertTrue(loan.line_ids)
+ self.assertEqual(len(loan.line_ids), periods)
+ line = loan.line_ids.filtered(lambda r: r.sequence == 1)
+ self.assertEqual(amount / periods, line.principal_amount)
+ self.assertEqual(amount / periods, line.long_term_principal_amount)
+ self.post(loan)
+ line = loan.line_ids.filtered(lambda r: r.sequence == 1)
+ self.assertTrue(line)
+ self.assertFalse(line.has_invoices)
+ self.assertFalse(line.has_moves)
+ self.env['account.loan.generate.wizard'].create({
+ 'date': fields.date.today(),
+ 'loan_type': 'leasing',
+ }).run()
+ self.assertTrue(line.has_invoices)
+ self.assertTrue(line.has_moves)
+
def test_interests_on_end_loan(self):
amount = 10000
periods = 10
diff --git a/account_loan/views/account_loan_view.xml b/account_loan/views/account_loan_view.xml
index f520408c..90ea9343 100644
--- a/account_loan/views/account_loan_view.xml
+++ b/account_loan/views/account_loan_view.xml
@@ -114,6 +114,7 @@
attrs="{'required': [('is_leasing', '=', True)]}"/>
+