fix: Pending shortfall update on processing loan security shortfall

This commit is contained in:
Deepesh Garg 2021-03-22 18:33:55 +05:30
parent b74436d535
commit f112ce14cf

View File

@ -55,6 +55,9 @@ def check_for_ltv_shortfall(process_loan_security_shortfall):
'total_interest_payable', 'disbursed_amount', 'status'],
filters={'status': ('in',['Disbursed','Partially Disbursed']), 'is_secured_loan': 1})
loan_shortfall_map = frappe._dict(frappe.get_all("Loan Security Shortfall",
fields=["loan", "name"], filters={"status": "Pending"}, as_list=1))
loan_security_map = {}
for loan in loans:
@ -71,14 +74,19 @@ def check_for_ltv_shortfall(process_loan_security_shortfall):
for security, qty in pledged_securities.items():
if not ltv_ratio:
ltv_ratio = get_ltv_ratio(security)
security_value += loan_security_price_map.get(security) * qty
security_value += flt(loan_security_price_map.get(security)) * flt(qty)
current_ratio = (outstanding_amount/security_value) * 100
current_ratio = (outstanding_amount/security_value) * 100 if security_value else 0
if current_ratio > ltv_ratio:
shortfall_amount = outstanding_amount - ((security_value * ltv_ratio) / 100)
create_loan_security_shortfall(loan.name, outstanding_amount, security_value, shortfall_amount,
process_loan_security_shortfall)
elif loan_shortfall_map.get(loan.name):
shortfall_amount = outstanding_amount - ((security_value * ltv_ratio) / 100)
if shortfall_amount <= 0:
shortfall = loan_shortfall_map.get(loan.name)
update_pending_shortfall(shortfall)
def create_loan_security_shortfall(loan, loan_amount, security_value, shortfall_amount, process_loan_security_shortfall):
existing_shortfall = frappe.db.get_value("Loan Security Shortfall", {"loan": loan, "status": "Pending"}, "name")
@ -101,3 +109,11 @@ def get_ltv_ratio(loan_security):
ltv_ratio = frappe.db.get_value('Loan Security Type', loan_security_type, 'loan_to_value_ratio')
return ltv_ratio
def update_pending_shortfall(shortfall):
# Get all pending loan security shortfall
frappe.db.set_value("Loan Security Shortfall", shortfall,
{
"status": "Completed",
"shortfall_amount": 0
})