fix: Add total loan interest amount field in loans
This commit is contained in:
parent
c7aecb8148
commit
1b208e0695
@ -22,6 +22,7 @@
|
|||||||
"paid_principal_amount",
|
"paid_principal_amount",
|
||||||
"column_break_14",
|
"column_break_14",
|
||||||
"interest_amount",
|
"interest_amount",
|
||||||
|
"total_pending_interest_amount",
|
||||||
"paid_interest_amount",
|
"paid_interest_amount",
|
||||||
"penalty_amount",
|
"penalty_amount",
|
||||||
"section_break_15",
|
"section_break_15",
|
||||||
@ -172,13 +173,19 @@
|
|||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Last Accrual Date",
|
"label": "Last Accrual Date",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "total_pending_interest_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Total Pending Interest Amount",
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-11-07 05:49:25.448875",
|
"modified": "2021-01-10 00:15:21.544140",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Loan Management",
|
"module": "Loan Management",
|
||||||
"name": "Loan Interest Accrual",
|
"name": "Loan Interest Accrual",
|
||||||
|
|||||||
@ -100,6 +100,8 @@ def calculate_accrual_amount_for_demand_loans(loan, posting_date, process_loan_i
|
|||||||
interest_per_day = get_per_day_interest(pending_principal_amount, loan.rate_of_interest, posting_date)
|
interest_per_day = get_per_day_interest(pending_principal_amount, loan.rate_of_interest, posting_date)
|
||||||
payable_interest = interest_per_day * no_of_days
|
payable_interest = interest_per_day * no_of_days
|
||||||
|
|
||||||
|
pending_amounts = calculate_amounts(loan.name, posting_date, payment_type='Loan Closure')
|
||||||
|
|
||||||
args = frappe._dict({
|
args = frappe._dict({
|
||||||
'loan': loan.name,
|
'loan': loan.name,
|
||||||
'applicant_type': loan.applicant_type,
|
'applicant_type': loan.applicant_type,
|
||||||
@ -108,7 +110,8 @@ def calculate_accrual_amount_for_demand_loans(loan, posting_date, process_loan_i
|
|||||||
'loan_account': loan.loan_account,
|
'loan_account': loan.loan_account,
|
||||||
'pending_principal_amount': pending_principal_amount,
|
'pending_principal_amount': pending_principal_amount,
|
||||||
'interest_amount': payable_interest,
|
'interest_amount': payable_interest,
|
||||||
'penalty_amount': calculate_amounts(loan.name, posting_date)['penalty_amount'],
|
'total_pending_interest_amount': pending_amounts['interest_amount'],
|
||||||
|
'penalty_amount': pending_amounts['penalty_amount'],
|
||||||
'process_loan_interest': process_loan_interest,
|
'process_loan_interest': process_loan_interest,
|
||||||
'posting_date': posting_date,
|
'posting_date': posting_date,
|
||||||
'accrual_type': accrual_type
|
'accrual_type': accrual_type
|
||||||
@ -202,6 +205,7 @@ def make_loan_interest_accrual_entry(args):
|
|||||||
loan_interest_accrual.loan_account = args.loan_account
|
loan_interest_accrual.loan_account = args.loan_account
|
||||||
loan_interest_accrual.pending_principal_amount = flt(args.pending_principal_amount, precision)
|
loan_interest_accrual.pending_principal_amount = flt(args.pending_principal_amount, precision)
|
||||||
loan_interest_accrual.interest_amount = flt(args.interest_amount, precision)
|
loan_interest_accrual.interest_amount = flt(args.interest_amount, precision)
|
||||||
|
loan_interest_accrual.total_pending_interest_amount = flt(args.total_pending_interest_amount, precision)
|
||||||
loan_interest_accrual.penalty_amount = flt(args.penalty_amount, precision)
|
loan_interest_accrual.penalty_amount = flt(args.penalty_amount, precision)
|
||||||
loan_interest_accrual.posting_date = args.posting_date or nowdate()
|
loan_interest_accrual.posting_date = args.posting_date or nowdate()
|
||||||
loan_interest_accrual.process_loan_interest_accrual = args.process_loan_interest
|
loan_interest_accrual.process_loan_interest_accrual = args.process_loan_interest
|
||||||
|
|||||||
@ -37,10 +37,8 @@ class TestLoanInterestAccrual(unittest.TestCase):
|
|||||||
|
|
||||||
loan_application = create_loan_application('_Test Company', self.applicant, 'Demand Loan', pledge)
|
loan_application = create_loan_application('_Test Company', self.applicant, 'Demand Loan', pledge)
|
||||||
create_pledge(loan_application)
|
create_pledge(loan_application)
|
||||||
|
|
||||||
loan = create_demand_loan(self.applicant, "Demand Loan", loan_application,
|
loan = create_demand_loan(self.applicant, "Demand Loan", loan_application,
|
||||||
posting_date=get_first_day(nowdate()))
|
posting_date=get_first_day(nowdate()))
|
||||||
|
|
||||||
loan.submit()
|
loan.submit()
|
||||||
|
|
||||||
first_date = '2019-10-01'
|
first_date = '2019-10-01'
|
||||||
@ -50,11 +48,46 @@ class TestLoanInterestAccrual(unittest.TestCase):
|
|||||||
|
|
||||||
accrued_interest_amount = (loan.loan_amount * loan.rate_of_interest * no_of_days) \
|
accrued_interest_amount = (loan.loan_amount * loan.rate_of_interest * no_of_days) \
|
||||||
/ (days_in_year(get_datetime(first_date).year) * 100)
|
/ (days_in_year(get_datetime(first_date).year) * 100)
|
||||||
|
|
||||||
make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date)
|
make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date)
|
||||||
|
|
||||||
process_loan_interest_accrual_for_demand_loans(posting_date=last_date)
|
process_loan_interest_accrual_for_demand_loans(posting_date=last_date)
|
||||||
|
|
||||||
loan_interest_accural = frappe.get_doc("Loan Interest Accrual", {'loan': loan.name})
|
loan_interest_accural = frappe.get_doc("Loan Interest Accrual", {'loan': loan.name})
|
||||||
|
|
||||||
self.assertEquals(flt(loan_interest_accural.interest_amount, 0), flt(accrued_interest_amount, 0))
|
self.assertEquals(flt(loan_interest_accural.interest_amount, 0), flt(accrued_interest_amount, 0))
|
||||||
|
|
||||||
|
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.assertEquals(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.assertEquals(flt(loan_interest_accrual.total_pending_interest_amount, 0), total_pending_interest_amount)
|
||||||
|
|||||||
@ -377,7 +377,7 @@ def get_amounts(amounts, against_loan, posting_date):
|
|||||||
amounts["penalty_amount"] = flt(penalty_amount, precision)
|
amounts["penalty_amount"] = flt(penalty_amount, precision)
|
||||||
amounts["payable_amount"] = flt(payable_principal_amount + total_pending_interest + penalty_amount, precision)
|
amounts["payable_amount"] = flt(payable_principal_amount + total_pending_interest + penalty_amount, precision)
|
||||||
amounts["pending_accrual_entries"] = pending_accrual_entries
|
amounts["pending_accrual_entries"] = pending_accrual_entries
|
||||||
amounts["unaccrued_interest"] = unaccrued_interest
|
amounts["unaccrued_interest"] = flt(unaccrued_interest, precision)
|
||||||
|
|
||||||
if final_due_date:
|
if final_due_date:
|
||||||
amounts["due_date"] = final_due_date
|
amounts["due_date"] = final_due_date
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user