[IMP] Account_loan: Add the option to automatically post invoices
This commit is contained in:
parent
21282d21a2
commit
d32fa82f95
@ -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",
|
||||
|
@ -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)',
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -114,6 +114,7 @@
|
||||
attrs="{'required': [('is_leasing', '=', True)]}"/>
|
||||
<field name="interests_product_id"
|
||||
attrs="{'required': [('is_leasing', '=', True)]}"/>
|
||||
<field name="post_invoice"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
Loading…
Reference in New Issue
Block a user