Skip to content

Commit

Permalink
Merge pull request #31258 from deepeshgarg007/unsecured_term_loan_clo…
Browse files Browse the repository at this point in the history
…sure

fix: Close unsecured terms loans
  • Loading branch information
deepeshgarg007 authored Jun 7, 2022
2 parents eae4f64 + 815141b commit 20c2ffa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
18 changes: 18 additions & 0 deletions erpnext/loan_management/doctype/loan/loan.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ frappe.ui.form.on('Loan', {
frm.trigger("make_loan_refund");
},__('Create'));
}

if (frm.doc.status == "Loan Closure Requested" && frm.doc.is_term_loan && !frm.doc.is_secured_loan) {
frm.add_custom_button(__('Close Loan'), function() {
frm.trigger("close_unsecured_term_loan");
},__('Status'));
}
}
frm.trigger("toggle_fields");
},
Expand Down Expand Up @@ -174,6 +180,18 @@ frappe.ui.form.on('Loan', {
})
},

close_unsecured_term_loan: function(frm) {
frappe.call({
args: {
"loan": frm.doc.name
},
method: "erpnext.loan_management.doctype.loan.loan.close_unsecured_term_loan",
callback: function () {
frm.refresh();
}
})
},

request_loan_closure: function(frm) {
frappe.confirm(__("Do you really want to close this loan"),
function() {
Expand Down
22 changes: 19 additions & 3 deletions erpnext/loan_management/doctype/loan/loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def validate_accounts(self):
)

def validate_cost_center(self):
if not self.cost_center and self.rate_of_interest != 0:
if not self.cost_center and self.rate_of_interest != 0.0:
self.cost_center = frappe.db.get_value("Company", self.company, "cost_center")

if not self.cost_center:
frappe.throw(_("Cost center is mandatory for loans having rate of interest greater than 0"))
if not self.cost_center:
frappe.throw(_("Cost center is mandatory for loans having rate of interest greater than 0"))

def on_submit(self):
self.link_loan_security_pledge()
Expand Down Expand Up @@ -342,6 +342,22 @@ def get_loan_application(loan_application):
return loan.as_dict()


@frappe.whitelist()
def close_unsecured_term_loan(loan):
loan_details = frappe.db.get_value(
"Loan", {"name": loan}, ["status", "is_term_loan", "is_secured_loan"], as_dict=1
)

if (
loan_details.status == "Loan Closure Requested"
and loan_details.is_term_loan
and not loan_details.is_secured_loan
):
frappe.db.set_value("Loan", loan, "status", "Closed")
else:
frappe.throw(_("Cannot close this loan until full repayment"))


def close_loan(loan, total_amount_paid):
frappe.db.set_value("Loan", loan, "total_amount_paid", total_amount_paid)
frappe.db.set_value("Loan", loan, "status", "Closed")
Expand Down

0 comments on commit 20c2ffa

Please sign in to comment.