From 6d27adccfce718c37b0a019fdf164c685c8271eb Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 10 Oct 2020 23:28:39 +0530 Subject: [PATCH] fix: Button to close loan --- erpnext/loan_management/doctype/loan/loan.js | 40 ++++++++++++++++---- erpnext/loan_management/loan_common.js | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/loan.js b/erpnext/loan_management/doctype/loan/loan.js index 9b4c21770e..682b574fea 100644 --- a/erpnext/loan_management/doctype/loan/loan.js +++ b/erpnext/loan_management/doctype/loan/loan.js @@ -21,6 +21,14 @@ frappe.ui.form.on('Loan', { }; }); + frm.set_query("loan_type", function () { + return { + "filters": { + "docstatus": 1 + } + }; + }); + $.each(["penalty_income_account", "interest_income_account"], function(i, field) { frm.set_query(field, function () { return { @@ -49,19 +57,21 @@ frappe.ui.form.on('Loan', { refresh: function (frm) { if (frm.doc.docstatus == 1) { + if (["Disbursed", "Partially Disbursed"].includes(frm.doc.status) && (!frm.doc.repay_from_salary)) { + frm.add_custom_button(__('Request Loan Closure'), function() { + frm.trigger("request_loan_closure"); + },__('Status')); + frm.add_custom_button(__('Loan Repayment'), function() { + frm.trigger("make_repayment_entry"); + },__('Create')); + } + if (frm.doc.status == "Sanctioned" || frm.doc.status == 'Partially Disbursed') { frm.add_custom_button(__('Loan Disbursement'), function() { frm.trigger("make_loan_disbursement"); },__('Create')); } - if (["Disbursed", "Partially Disbursed"].includes(frm.doc.status) && (!frm.doc.repay_from_salary)) { - frm.add_custom_button(__('Loan Repayment'), function() { - frm.trigger("make_repayment_entry"); - },__('Create')); - - } - if (frm.doc.status == "Loan Closure Requested") { frm.add_custom_button(__('Loan Security Unpledge'), function() { frm.trigger("create_loan_security_unpledge"); @@ -117,6 +127,22 @@ frappe.ui.form.on('Loan', { }) }, + request_loan_closure: function(frm) { + frappe.confirm(__("Do you really want to close this loan"), + function() { + frappe.call({ + args: { + 'loan': frm.doc.name + }, + method: "erpnext.loan_management.doctype.loan.loan.request_loan_closure", + callback: function() { + frm.reload_doc(); + } + }); + } + ); + }, + create_loan_security_unpledge: function(frm) { frappe.call({ method: "erpnext.loan_management.doctype.loan.loan.unpledge_security", diff --git a/erpnext/loan_management/loan_common.js b/erpnext/loan_management/loan_common.js index d9dd415296..33a5de0566 100644 --- a/erpnext/loan_management/loan_common.js +++ b/erpnext/loan_management/loan_common.js @@ -15,7 +15,7 @@ frappe.ui.form.on(cur_frm.doctype, { frappe.route_options = { voucher_no: frm.doc.name, company: frm.doc.company, - from_date: frm.doc.posting_date, + from_date: moment(frm.doc.posting_date).format('YYYY-MM-DD'), to_date: moment(frm.doc.modified).format('YYYY-MM-DD'), show_cancelled_entries: frm.doc.docstatus === 2 };