fix: Allow repayment from Salary only for term loans
diff --git a/erpnext/loan_management/doctype/loan/loan.json b/erpnext/loan_management/doctype/loan/loan.json
index 2834e5b..b04e822 100644
--- a/erpnext/loan_management/doctype/loan/loan.json
+++ b/erpnext/loan_management/doctype/loan/loan.json
@@ -126,7 +126,7 @@
"depends_on": "eval:doc.applicant_type==\"Employee\"",
"fieldname": "repay_from_salary",
"fieldtype": "Check",
- "label": "Repay from Salary"
+ "label": "Repay From Salary"
},
{
"fieldname": "section_break_8",
@@ -178,6 +178,8 @@
},
{
"depends_on": "is_term_loan",
+ "fetch_from": "loan_application.repayment_amount",
+ "fetch_if_empty": 1,
"fieldname": "monthly_repayment_amount",
"fieldtype": "Currency",
"label": "Monthly Repayment Amount",
@@ -350,7 +352,7 @@
],
"is_submittable": 1,
"links": [],
- "modified": "2020-02-07 01:31:25.172173",
+ "modified": "2020-04-13 13:16:10.192624",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan",
diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py
index eb5f127..c7a2fba 100644
--- a/erpnext/loan_management/doctype/loan/loan.py
+++ b/erpnext/loan_management/doctype/loan/loan.py
@@ -19,6 +19,7 @@
self.validate_loan_security_pledge()
self.validate_loan_amount()
self.check_sanctioned_amount_limit()
+ self.validate_repay_from_salary()
if self.is_term_loan:
validate_repayment_method(self.repayment_method, self.loan_amount, self.monthly_repayment_amount,
@@ -77,6 +78,10 @@
if sanctioned_amount_limit and flt(self.loan_amount) + flt(total_loan_amount) > flt(sanctioned_amount_limit):
frappe.throw(_("Sanctioned Amount limit crossed for {0} {1}").format(self.applicant_type, frappe.bold(self.applicant)))
+ def validate_repay_from_salary(self):
+ if not self.is_term_loan and self.repay_from_salary:
+ frappe.throw(_("Repay From Salary can be selected only for term loans"))
+
def make_repayment_schedule(self):
if not self.repayment_start_date:
diff --git a/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.py b/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.py
index 417e367..b4aad25 100644
--- a/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.py
+++ b/erpnext/loan_management/doctype/process_loan_security_shortfall/process_loan_security_shortfall.py
@@ -14,4 +14,13 @@
self.set_onload('update_time', get_datetime())
def on_submit(self):
- check_for_ltv_shortfall(process_loan_security_shortfall = self.name)
+ check_for_ltv_shortfall(self.name)
+
+def create_process_loan_security_shortfall():
+ if check_for_secured_loans():
+ process = frappe.new_doc("Process Loan Security Shortfall")
+ process.update_time = get_datetime()
+ process.submit()
+
+def check_for_secured_loans():
+ return frappe.db.count('Loan', {'docstatus': 1, 'is_secured_loan': 1})