Merge pull request #20781 from deepeshgarg007/loan_shortfall_enhance

fix: Add loan to value ratio in loan security type
This commit is contained in:
Deepesh Garg 2020-02-29 09:01:27 +05:30 committed by GitHub
commit 2090d113e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -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):

View File

@ -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",