fix: Validate loan repayment amount in Loan Application (#18169)
* fix: validate loan repayment amount * fix: test for loan application
This commit is contained in:
parent
1ac9a8e82e
commit
e37ff39836
@ -29,9 +29,12 @@ class LoanApplication(Document):
|
|||||||
if self.repayment_method == "Repay Fixed Amount per Period":
|
if self.repayment_method == "Repay Fixed Amount per Period":
|
||||||
monthly_interest_rate = flt(self.rate_of_interest) / (12 *100)
|
monthly_interest_rate = flt(self.rate_of_interest) / (12 *100)
|
||||||
if monthly_interest_rate:
|
if monthly_interest_rate:
|
||||||
self.repayment_periods = math.ceil((math.log(self.repayment_amount) -
|
min_repayment_amount = self.loan_amount*monthly_interest_rate
|
||||||
math.log(self.repayment_amount - (self.loan_amount*monthly_interest_rate))) /
|
if self.repayment_amount - min_repayment_amount < 0:
|
||||||
(math.log(1 + monthly_interest_rate)))
|
frappe.throw(_("Repayment Amount must be greater than " \
|
||||||
|
+ str(flt(min_repayment_amount, 2))))
|
||||||
|
self.repayment_periods = math.ceil(math.log(self.repayment_amount) -
|
||||||
|
math.log(self.repayment_amount - min_repayment_amount) /(math.log(1 + monthly_interest_rate)))
|
||||||
else:
|
else:
|
||||||
self.repayment_periods = self.loan_amount / self.repayment_amount
|
self.repayment_periods = self.loan_amount / self.repayment_amount
|
||||||
|
|
||||||
|
@ -31,21 +31,22 @@ class TestLoanApplication(unittest.TestCase):
|
|||||||
"rate_of_interest": 9.2,
|
"rate_of_interest": 9.2,
|
||||||
"loan_amount": 250000,
|
"loan_amount": 250000,
|
||||||
"repayment_method": "Repay Over Number of Periods",
|
"repayment_method": "Repay Over Number of Periods",
|
||||||
"repayment_periods": 24
|
"repayment_periods": 18
|
||||||
})
|
})
|
||||||
loan_application.insert()
|
loan_application.insert()
|
||||||
|
|
||||||
|
|
||||||
def test_loan_totals(self):
|
def test_loan_totals(self):
|
||||||
loan_application = frappe.get_doc("Loan Application", {"applicant":self.applicant})
|
loan_application = frappe.get_doc("Loan Application", {"applicant":self.applicant})
|
||||||
self.assertEquals(loan_application.repayment_amount, 11445)
|
|
||||||
self.assertEquals(loan_application.total_payable_interest, 24657)
|
|
||||||
self.assertEquals(loan_application.total_payable_amount, 274657)
|
|
||||||
|
|
||||||
loan_application.repayment_method = "Repay Fixed Amount per Period"
|
self.assertEqual(loan_application.total_payable_interest, 18599)
|
||||||
loan_application.repayment_amount = 15000
|
self.assertEqual(loan_application.total_payable_amount, 268599)
|
||||||
|
self.assertEqual(loan_application.repayment_amount, 14923)
|
||||||
|
|
||||||
|
loan_application.repayment_periods = 24
|
||||||
loan_application.save()
|
loan_application.save()
|
||||||
|
loan_application.reload()
|
||||||
|
|
||||||
self.assertEqual(loan_application.repayment_periods, 18)
|
self.assertEqual(loan_application.total_payable_interest, 24657)
|
||||||
self.assertEqual(loan_application.total_payable_interest, 18506)
|
self.assertEqual(loan_application.total_payable_amount, 274657)
|
||||||
self.assertEqual(loan_application.total_payable_amount, 268506)
|
self.assertEqual(loan_application.repayment_amount, 11445)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user