fix: Close unsecured terms loans

This commit is contained in:
Deepesh Garg 2022-06-07 13:16:06 +05:30
parent c7efa3b44d
commit 815141bf57
2 changed files with 37 additions and 3 deletions

View File

@ -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");
},
@ -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() {

View File

@ -60,11 +60,11 @@ class Loan(AccountsController):
)
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()
@ -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")