feat: Loan Exposure report

This commit is contained in:
Deepesh Garg 2021-01-17 11:36:51 +05:30
parent 7976d12ed0
commit addea9697d
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Loan Security Exposure"] = {
"filters": [
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"default": frappe.defaults.get_user_default("Company"),
"reqd": 1
}
]
};

View File

@ -0,0 +1,29 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2021-01-16 08:08:01.694583",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"modified": "2021-01-16 08:08:01.694583",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Security Exposure",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Loan Security",
"report_name": "Loan Security Exposure",
"report_type": "Script Report",
"roles": [
{
"role": "System Manager"
},
{
"role": "Loan Manager"
}
]
}

View File

@ -0,0 +1,77 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import get_datetime, flt
from six import iteritems
from erpnext.loan_management.report.applicant_wise_loan_security_exposure.applicant_wise_loan_security_exposure \
import get_loan_security_details, get_applicant_wise_total_loan_security_qty
def execute(filters=None):
columns = get_columns(filters)
data = get_data(filters)
return columns, data
def get_columns(filters):
columns = [
{"label": _("Loan Security"), "fieldname": "loan_security", "fieldtype": "Link", "options": "Loan Security", "width": 160},
{"label": _("Loan Security Code"), "fieldname": "loan_security_code", "fieldtype": "Data", "width": 100},
{"label": _("Loan Security Name"), "fieldname": "loan_security_name", "fieldtype": "Data", "width": 150},
{"label": _("Haircut"), "fieldname": "haircut", "fieldtype": "Percent", "width": 100},
{"label": _("Loan Security Type"), "fieldname": "loan_security_type", "fieldtype": "Link", "options": "Loan Security Type", "width": 120},
{"label": _("Disabled"), "fieldname": "disabled", "fieldtype": "Check", "width": 80},
{"label": _("Total Qty"), "fieldname": "total_qty", "fieldtype": "Float", "width": 100},
{"label": _("Latest Price"), "fieldname": "latest_price", "fieldtype": "Currency", "options": "Currency", "width": 100},
{"label": _("Current Value"), "fieldname": "current_value", "fieldtype": "Currency", "options": "Currency", "width": 100},
{"label": _("% Of Total Portfolio"), "fieldname": "portfolio_percent", "fieldtype": "Percentage", "width": 100},
{"label": _("Pledged Applicant Count"), "fieldname": "pledged_applicant_count", "fieldtype": "Percentage", "width": 100},
]
return columns
def get_data(filters):
data = []
loan_security_details = get_loan_security_details(filters)
current_pledges, total_portfolio_value = get_company_wise_loan_security_details(filters, loan_security_details)
for security, value in iteritems(current_pledges):
row = {}
current_value = flt(value['qty'] * loan_security_details.get(security)['latest_price'])
row.update(loan_security_details.get(security))
row.update({
'total_qty': value['qty'],
'current_value': current_value,
'portfolio_percent': current_value * 100 / total_portfolio_value,
'pledged_applicant_count': value['applicant_count']
})
data.append(row)
return data
def get_company_wise_loan_security_details(filters, loan_security_details):
pledge_values, total_value_map, applicant_type_map = get_applicant_wise_total_loan_security_qty(filters,
loan_security_details)
total_portfolio_value = 0
security_wise_map = {}
for key, qty in iteritems(pledge_values):
security_wise_map.setdefault(key[1], {
'qty': 0.0,
'applicant_count': 0.0
})
security_wise_map[key[1]]['qty'] += qty
if qty:
security_wise_map[key[1]]['applicant_count'] += 1
total_portfolio_value += flt(qty * loan_security_details.get(key[1])['latest_price'])
return security_wise_map, total_portfolio_value