fix: Division by 0 error in security exposure reports
diff --git a/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.py b/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.py
index f280402..ab586bc 100644
--- a/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.py
+++ b/erpnext/loan_management/report/applicant_wise_loan_security_exposure/applicant_wise_loan_security_exposure.py
@@ -43,22 +43,24 @@
currency = erpnext.get_company_currency(filters.get('company'))
for key, qty in iteritems(pledge_values):
- row = {}
- current_value = flt(qty * loan_security_details.get(key[1], {}).get('latest_price', 0))
- valid_upto = loan_security_details.get(key[1], {}).get('valid_upto')
+ if qty:
+ row = {}
+ current_value = flt(qty * loan_security_details.get(key[1], {}).get('latest_price', 0))
+ valid_upto = loan_security_details.get(key[1], {}).get('valid_upto')
- row.update(loan_security_details.get(key[1]))
- row.update({
- 'applicant_type': applicant_type_map.get(key[0]),
- 'applicant_name': key[0],
- 'total_qty': qty,
- 'current_value': current_value,
- 'price_valid_upto': valid_upto,
- 'portfolio_percent': flt(current_value * 100 / total_value_map.get(key[0]), 2),
- 'currency': currency
- })
+ row.update(loan_security_details.get(key[1]))
+ row.update({
+ 'applicant_type': applicant_type_map.get(key[0]),
+ 'applicant_name': key[0],
+ 'total_qty': qty,
+ 'current_value': current_value,
+ 'price_valid_upto': valid_upto,
+ 'portfolio_percent': flt(current_value * 100 / total_value_map.get(key[0]), 2) if total_value_map.get(key[0]) \
+ else 0.0,
+ 'currency': currency
+ })
- data.append(row)
+ data.append(row)
return data
diff --git a/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.py b/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.py
index ff88052..adc8013 100644
--- a/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.py
+++ b/erpnext/loan_management/report/loan_security_exposure/loan_security_exposure.py
@@ -40,21 +40,22 @@
currency = erpnext.get_company_currency(filters.get('company'))
for security, value in iteritems(current_pledges):
- row = {}
- current_value = flt(value.get('qty', 0) * loan_security_details.get(security, {}).get('latest_price', 0))
- valid_upto = loan_security_details.get(security, {}).get('valid_upto')
+ if value.get('qty'):
+ row = {}
+ current_value = flt(value.get('qty', 0) * loan_security_details.get(security, {}).get('latest_price', 0))
+ valid_upto = loan_security_details.get(security, {}).get('valid_upto')
- row.update(loan_security_details.get(security))
- row.update({
- 'total_qty': value.get('qty'),
- 'current_value': current_value,
- 'price_valid_upto': valid_upto,
- 'portfolio_percent': flt(current_value * 100 / total_portfolio_value, 2),
- 'pledged_applicant_count': value.get('applicant_count'),
- 'currency': currency
- })
+ row.update(loan_security_details.get(security))
+ row.update({
+ 'total_qty': value.get('qty'),
+ 'current_value': current_value,
+ 'price_valid_upto': valid_upto,
+ 'portfolio_percent': flt(current_value * 100 / total_portfolio_value, 2),
+ 'pledged_applicant_count': value.get('applicant_count'),
+ 'currency': currency
+ })
- data.append(row)
+ data.append(row)
return data