mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
Merge pull request #24971 from deepeshgarg007/loan_security_shortfall_process_update
fix: Pending shortfall update on processing loan security shortfall
This commit is contained in:
@@ -275,6 +275,11 @@ class TestLoan(unittest.TestCase):
|
|||||||
frappe.db.sql(""" UPDATE `tabLoan Security Price` SET loan_security_price = 250
|
frappe.db.sql(""" UPDATE `tabLoan Security Price` SET loan_security_price = 250
|
||||||
where loan_security='Test Security 2'""")
|
where loan_security='Test Security 2'""")
|
||||||
|
|
||||||
|
create_process_loan_security_shortfall()
|
||||||
|
loan_security_shortfall = frappe.get_doc("Loan Security Shortfall", {"loan": loan.name})
|
||||||
|
self.assertEquals(loan_security_shortfall.status, "Completed")
|
||||||
|
self.assertEquals(loan_security_shortfall.shortfall_amount, 0)
|
||||||
|
|
||||||
def test_loan_security_unpledge(self):
|
def test_loan_security_unpledge(self):
|
||||||
pledge = [{
|
pledge = [{
|
||||||
"loan_security": "Test Security 1",
|
"loan_security": "Test Security 1",
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ def check_for_ltv_shortfall(process_loan_security_shortfall):
|
|||||||
'total_interest_payable', 'disbursed_amount', 'status'],
|
'total_interest_payable', 'disbursed_amount', 'status'],
|
||||||
filters={'status': ('in',['Disbursed','Partially Disbursed']), 'is_secured_loan': 1})
|
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 = {}
|
loan_security_map = {}
|
||||||
|
|
||||||
for loan in loans:
|
for loan in loans:
|
||||||
@@ -71,14 +74,19 @@ def check_for_ltv_shortfall(process_loan_security_shortfall):
|
|||||||
for security, qty in pledged_securities.items():
|
for security, qty in pledged_securities.items():
|
||||||
if not ltv_ratio:
|
if not ltv_ratio:
|
||||||
ltv_ratio = get_ltv_ratio(security)
|
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:
|
if current_ratio > ltv_ratio:
|
||||||
shortfall_amount = outstanding_amount - ((security_value * ltv_ratio) / 100)
|
shortfall_amount = outstanding_amount - ((security_value * ltv_ratio) / 100)
|
||||||
create_loan_security_shortfall(loan.name, outstanding_amount, security_value, shortfall_amount,
|
create_loan_security_shortfall(loan.name, outstanding_amount, security_value, shortfall_amount,
|
||||||
process_loan_security_shortfall)
|
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):
|
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")
|
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')
|
ltv_ratio = frappe.db.get_value('Loan Security Type', loan_security_type, 'loan_to_value_ratio')
|
||||||
return ltv_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
|
||||||
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user