Skip to content

Commit

Permalink
Update test_loan_permanent.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasramossomit committed Oct 16, 2024
1 parent c18d334 commit 7ce0016
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions account_loan_permanent/tests/test_loan_permanent.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,50 @@ def test_create_next_line(self):
self.assertEqual(
new_line.pending_principal_amount, last_line.final_pending_principal_amount
)

def test_onchange_is_permanent_with_interest_type(self):
"""Test onchange behavior when loan type is 'interest'."""
self.test_loan.loan_type = "interest"
self.test_loan.is_permanent = True
self.test_loan._onchange_is_permanent()
self.assertTrue(self.test_loan.is_permanent)
self.assertEqual(self.test_loan.residual_amount, 0)
self.assertGreaterEqual(self.test_loan.periods, self.test_loan.min_periods)

def test_generate_loan_entries_for_permanent_loan(self):
"""Test generation of loan entries for permanent loans."""
self.test_loan.start_date = fields.Date.today() - relativedelta(months=2)
self.test_loan.post()
future_date = fields.Date.today() + relativedelta(months=3)
self.loan_model._generate_loan_entries(future_date)
self.assertGreater(len(self.test_loan.line_ids), self.test_loan.min_periods)
last_line = self.test_loan.line_ids.sorted(key=lambda r: r.sequence)[-1]
self.assertGreater(last_line.date, future_date)

def test_create_next_line_for_permanent_loan(self):
"""Test creation of next line for permanent loans."""
self.test_loan.post()
last_line = self.test_loan.line_ids.sorted(key=lambda r: r.sequence)[-1]
new_line = self.env['account.loan.line']._create_next_line(last_line)
self.assertEqual(new_line.sequence, last_line.sequence + 1)
self.assertEqual(new_line.date, last_line.date + relativedelta(months=1))
self.assertEqual(new_line.pending_principal_amount, self.test_loan.loan_amount)
self.assertEqual(new_line.long_term_pending_principal_amount, self.test_loan.loan_amount)

def test_compute_interests_for_permanent_loan(self):
"""Test interest computation for permanent loans."""
self.test_loan.post()
line = self.test_loan.line_ids[0]
line._compute_interests()
expected_interest = self.test_loan.loan_amount * self.test_loan.rate_period / 100
self.assertAlmostEqual(line.interests_amount, expected_interest, places=2)

def test_compute_amount_for_permanent_loan(self):
"""Test amount computation for permanent loans."""
self.test_loan.post()
line = self.test_loan.line_ids[0]
line._compute_amount()
self.assertEqual(line.payment_amount, line.interests_amount)
self.assertEqual(line.principal_amount, 0)
self.assertEqual(line.pending_principal_amount, self.test_loan.loan_amount)
self.assertEqual(line.final_pending_principal_amount, self.test_loan.loan_amount)

0 comments on commit 7ce0016

Please sign in to comment.