From 66967c6d450f5d83cf6d999ecb4b5516fd71a050 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 13 Oct 2020 18:10:51 +0530 Subject: [PATCH] fix: Loan Security unpledge on loan cancel --- erpnext/loan_management/doctype/loan/loan.js | 3 +++ erpnext/loan_management/doctype/loan/loan.py | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/loan.js b/erpnext/loan_management/doctype/loan/loan.js index 682b574fea..0dc3bf8563 100644 --- a/erpnext/loan_management/doctype/loan/loan.js +++ b/erpnext/loan_management/doctype/loan/loan.js @@ -11,6 +11,9 @@ frappe.ui.form.on('Loan', { } }, onload: function (frm) { + // Ignore loan security pledge on cancel of loan + frm.ignore_doctypes_on_cancel_all = ["Loan Security Pledge"]; + frm.set_query("loan_application", function () { return { "filters": { diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index 1fb0805d38..2d705fc296 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -138,9 +138,12 @@ class Loan(AccountsController): }) def unlink_loan_security_pledge(self): - frappe.db.sql("""UPDATE `tabLoan Security Pledge` SET - loan = '', status = 'Unpledged' - where name = %s """, (self.loan_security_pledge)) + pledges = frappe.get_all('Loan Security Pledge', fields=['name'], filters={'loan': self.name}) + pledge_list = [d.name for d in pledges] + if pledge_list: + frappe.db.sql("""UPDATE `tabLoan Security Pledge` SET + loan = '', status = 'Unpledged' + where name in (%s) """ % (', '.join(['%s']*len(pledge_list))), tuple(pledge_list)) def update_total_amount_paid(doc): total_amount_paid = 0