def test_loan_interest_accural(self): pledge = [{ "loan_security": "Test Security 1", "qty": 4000.00 }] loan_application = create_loan_application('_Test Company', self.applicant, 'Demand Loan', pledge) create_pledge(loan_application) loan = create_demand_loan(self.applicant, "Demand Loan", loan_application, posting_date=get_first_day(nowdate())) loan.submit() first_date = '2019-10-01' last_date = '2019-10-30' no_of_days = date_diff(last_date, first_date) + 1 accrued_interest_amount = (loan.loan_amount * loan.rate_of_interest * no_of_days) \ / (days_in_year(get_datetime(first_date).year) * 100) make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date) process_loan_interest_accrual_for_demand_loans(posting_date=last_date) loan_interest_accural = frappe.get_doc("Loan Interest Accrual", {'loan': loan.name}) self.assertEquals(flt(loan_interest_accural.interest_amount, 2), flt(accrued_interest_amount, 2))
def test_loan_topup(self): pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}] loan_application = create_loan_application("_Test Company", self.applicant, "Demand Loan", pledge) create_pledge(loan_application) loan = create_demand_loan(self.applicant, "Demand Loan", loan_application, posting_date=get_first_day(nowdate())) loan.submit() first_date = get_first_day(nowdate()) last_date = get_last_day(nowdate()) no_of_days = date_diff(last_date, first_date) + 1 accrued_interest_amount = (loan.loan_amount * loan.rate_of_interest * no_of_days) / ( days_in_year(get_datetime().year) * 100) make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date) process_loan_interest_accrual_for_demand_loans( posting_date=add_days(last_date, 1)) # Should not be able to create loan disbursement entry before repayment self.assertRaises(frappe.ValidationError, make_loan_disbursement_entry, loan.name, 500000, first_date) repayment_entry = create_repayment_entry( loan.name, self.applicant, add_days(get_last_day(nowdate()), 5), 611095.89) repayment_entry.submit() loan.reload() # After repayment loan disbursement entry should go through make_loan_disbursement_entry(loan.name, 500000, disbursement_date=add_days(last_date, 16)) # check for disbursement accrual loan_interest_accrual = frappe.db.get_value( "Loan Interest Accrual", { "loan": loan.name, "accrual_type": "Disbursement" }) self.assertTrue(loan_interest_accrual)
def test_accumulated_amounts(self): pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}] loan_application = create_loan_application("_Test Company", self.applicant, "Demand Loan", pledge) create_pledge(loan_application) loan = create_demand_loan(self.applicant, "Demand Loan", loan_application, posting_date=get_first_day(nowdate())) loan.submit() first_date = "2019-10-01" last_date = "2019-10-30" no_of_days = date_diff(last_date, first_date) + 1 accrued_interest_amount = ( loan.loan_amount * loan.rate_of_interest * no_of_days) / (days_in_year(get_datetime(first_date).year) * 100) make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date) process_loan_interest_accrual_for_demand_loans(posting_date=last_date) loan_interest_accrual = frappe.get_doc("Loan Interest Accrual", {"loan": loan.name}) self.assertEqual(flt(loan_interest_accrual.interest_amount, 0), flt(accrued_interest_amount, 0)) next_start_date = "2019-10-31" next_end_date = "2019-11-29" no_of_days = date_diff(next_end_date, next_start_date) + 1 process = process_loan_interest_accrual_for_demand_loans( posting_date=next_end_date) new_accrued_interest_amount = ( loan.loan_amount * loan.rate_of_interest * no_of_days) / (days_in_year(get_datetime(first_date).year) * 100) total_pending_interest_amount = flt( accrued_interest_amount + new_accrued_interest_amount, 0) loan_interest_accrual = frappe.get_doc( "Loan Interest Accrual", { "loan": loan.name, "process_loan_interest_accrual": process }) self.assertEqual( flt(loan_interest_accrual.total_pending_interest_amount, 0), total_pending_interest_amount)
def test_loan_topup_with_additional_pledge(self): pledge = [{ "loan_security": "Test Security 1", "qty": 4000.00 }] loan_application = create_loan_application( '_Test Company', self.applicant, 'Demand Loan', pledge) create_pledge(loan_application) loan = create_demand_loan( self.applicant, "Demand Loan", loan_application, posting_date='2019-10-01') loan.submit() self.assertEquals(loan.loan_amount, 1000000) first_date = '2019-10-01' last_date = '2019-10-30' # Disbursed 10,00,000 amount make_loan_disbursement_entry( loan.name, loan.loan_amount, disbursement_date=first_date) process_loan_interest_accrual_for_demand_loans(posting_date=last_date) amounts = calculate_amounts(loan.name, add_days(last_date, 1)) previous_interest = amounts['interest_amount'] pledge1 = [{ "loan_security": "Test Security 1", "qty": 2000.00 }] create_loan_security_pledge(self.applicant, pledge1, loan=loan.name) # Topup 500000 make_loan_disbursement_entry( loan.name, 500000, disbursement_date=add_days(last_date, 1)) process_loan_interest_accrual_for_demand_loans( posting_date=add_days(last_date, 15)) amounts = calculate_amounts(loan.name, add_days(last_date, 15)) per_day_interest = get_per_day_interest(1500000, 13.5, '2019-10-30') interest = per_day_interest * 15 self.assertEquals(amounts['pending_principal_amount'], 1500000) self.assertEquals(amounts['interest_amount'], flt(interest + previous_interest, 2))