fix: Allow repayment from Salary only for term loans

This commit is contained in:
Deepesh Garg 2020-04-13 13:18:11 +05:30
parent af27d61bee
commit baa7521d02
3 changed files with 19 additions and 3 deletions

View File

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

View File

@ -19,6 +19,7 @@ class Loan(AccountsController):
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 @@ class Loan(AccountsController):
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:

View File

@ -14,4 +14,13 @@ class ProcessLoanSecurityShortfall(Document):
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})