From eee7f77d477a4e7c146a7e7270ee2e76c63ee1de Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 29 Feb 2020 08:58:15 +0530 Subject: [PATCH] fix: Add loan to value ratio in loan security type --- .../loan_security_shortfall.py | 8 ++++++-- .../loan_security_type/loan_security_type.json | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py index 599f6dafaa..b7be84f836 100644 --- a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py +++ b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py @@ -55,7 +55,10 @@ def check_for_ltv_shortfall(process_loan_security_shortfall=None): "valid_upto": (">=", update_time) }, as_list=1)) - loans = frappe.db.sql(""" SELECT l.name, l.loan_amount, l.total_principal_paid, lp.loan_security, lp.haircut, lp.qty + ltv_ratio_map = frappe._dict(frappe.get_all("Loan Security Type", + fields=["name", "loan_to_value_ratio"], as_list=1)) + + loans = frappe.db.sql(""" SELECT l.name, l.loan_amount, l.total_principal_paid, lp.loan_security, lp.haircut, lp.qty, lp.loan_security_type FROM `tabLoan` l, `tabPledge` lp , `tabLoan Security Pledge`p WHERE lp.parent = p.name and p.loan = l.name and l.docstatus = 1 and l.is_secured_loan and l.status = 'Disbursed' and p.status in ('Pledged', 'Partially Unpledged')""", as_dict=1) @@ -68,11 +71,12 @@ def check_for_ltv_shortfall(process_loan_security_shortfall=None): }) current_loan_security_amount = loan_security_price_map.get(loan.loan_security, 0) * loan.qty + ltv_ratio = ltv_ratio_map.get(loan.loan_security_type) loan_security_map[loan.name]['security_value'] += current_loan_security_amount - (current_loan_security_amount * loan.haircut/100) for loan, value in iteritems(loan_security_map): - if value["security_value"] < value["loan_amount"]: + if (value["security_value"]/value["loan_amount"]) < ltv_ratio: create_loan_security_shortfall(loan, value, process_loan_security_shortfall) def create_loan_security_shortfall(loan, value, process_loan_security_shortfall): diff --git a/erpnext/loan_management/doctype/loan_security_type/loan_security_type.json b/erpnext/loan_management/doctype/loan_security_type/loan_security_type.json index a5ab057cdc..5f296093a4 100644 --- a/erpnext/loan_management/doctype/loan_security_type/loan_security_type.json +++ b/erpnext/loan_management/doctype/loan_security_type/loan_security_type.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "field:loan_security_type", "creation": "2019-08-29 18:46:07.322056", "doctype": "DocType", @@ -8,7 +9,9 @@ "loan_security_type", "unit_of_measure", "haircut", - "disabled" + "disabled", + "column_break_5", + "loan_to_value_ratio" ], "fields": [ { @@ -33,9 +36,19 @@ "fieldtype": "Link", "label": "Unit Of Measure", "options": "UOM" + }, + { + "fieldname": "column_break_5", + "fieldtype": "Column Break" + }, + { + "fieldname": "loan_to_value_ratio", + "fieldtype": "Percent", + "label": "Loan To Value Ratio" } ], - "modified": "2019-10-10 03:05:37.912866", + "links": [], + "modified": "2020-02-28 12:43:20.364447", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Security Type",