2
0

[IMP] Account_loan: Add the option to automatically post invoices

This commit is contained in:
Enric Tobella 2018-07-18 10:17:20 +02:00
parent 21282d21a2
commit d32fa82f95
5 changed files with 37 additions and 3 deletions

View File

@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Account Loan management", "name": "Account Loan management",
"version": "11.0.1.0.0", "version": "11.0.1.1.0",
"author": "Creu Blanca,Odoo Community Association (OCA)", "author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "http://github.com/OCA/account-financial-tools", "website": "http://github.com/OCA/account-financial-tools",
"license": "AGPL-3", "license": "AGPL-3",

View File

@ -241,6 +241,10 @@ class AccountLoan(models.Model):
string='Total interests payed', string='Total interests payed',
compute='_compute_total_amounts', compute='_compute_total_amounts',
) )
post_invoice = fields.Boolean(
default=True,
help='Invoices will be posted automatically'
)
_sql_constraints = [ _sql_constraints = [
('name_uniq', 'unique(name, company_id)', ('name_uniq', 'unique(name, company_id)',

View File

@ -328,6 +328,8 @@ class AccountLoanLine(models.Model):
for line in invoice.invoice_line_ids: for line in invoice.invoice_line_ids:
line._set_taxes() line._set_taxes()
invoice.compute_taxes() invoice.compute_taxes()
if record.loan_id.post_invoice:
invoice.action_invoice_open()
return res return res
@api.multi @api.multi

View File

@ -223,6 +223,7 @@ class TestLoan(TransactionCase):
self.partner.property_account_payable_id = self.payable_account self.partner.property_account_payable_id = self.payable_account
self.assertEqual(loan.journal_type, 'general') self.assertEqual(loan.journal_type, 'general')
loan.is_leasing = True loan.is_leasing = True
loan.post_invoice = False
self.assertEqual(loan.journal_type, 'purchase') self.assertEqual(loan.journal_type, 'purchase')
loan.long_term_loan_account_id = self.lt_loan_account loan.long_term_loan_account_id = self.lt_loan_account
loan.rate_type = 'real' loan.rate_type = 'real'
@ -243,8 +244,6 @@ class TestLoan(TransactionCase):
}).run() }).run()
self.assertTrue(line.has_invoices) self.assertTrue(line.has_invoices)
self.assertFalse(line.has_moves) 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]) self.assertIn(line.invoice_ids.id, action['domain'][0][2])
with self.assertRaises(UserError): with self.assertRaises(UserError):
self.env['account.loan.pay.amount'].create({ self.env['account.loan.pay.amount'].create({
@ -299,6 +298,34 @@ class TestLoan(TransactionCase):
with self.assertRaises(UserError): with self.assertRaises(UserError):
line.view_process_values() 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): def test_interests_on_end_loan(self):
amount = 10000 amount = 10000
periods = 10 periods = 10

View File

@ -114,6 +114,7 @@
attrs="{'required': [('is_leasing', '=', True)]}"/> attrs="{'required': [('is_leasing', '=', True)]}"/>
<field name="interests_product_id" <field name="interests_product_id"
attrs="{'required': [('is_leasing', '=', True)]}"/> attrs="{'required': [('is_leasing', '=', True)]}"/>
<field name="post_invoice"/>
</group> </group>
</group> </group>
</page> </page>