fix: Add loan to value ratio in loan security type
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 599f6da..b7be84f 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 @@
 			"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 @@
 		})
 
 		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 a5ab057..5f29609 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",