From 42a59d5c171da96bccaf657eb87454040a9cc84c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 12 Nov 2022 17:32:04 +0530 Subject: [PATCH 1/3] chore: Remove raw SQL query --- .../doctype/bank_guarantee/bank_guarantee.js | 13 ++------- .../doctype/bank_guarantee/bank_guarantee.py | 28 +++++++++---------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js index febf85ca6c..99cc0a72fb 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js @@ -43,20 +43,13 @@ frappe.ui.form.on('Bank Guarantee', { reference_docname: function(frm) { if (frm.doc.reference_docname && frm.doc.reference_doctype) { - let fields_to_fetch = ["grand_total"]; let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier"; - if (frm.doc.reference_doctype == "Sales Order") { - fields_to_fetch.push("project"); - } - - fields_to_fetch.push(party_field); frappe.call({ - method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_vouchar_detials", + method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details", args: { - "column_list": fields_to_fetch, - "doctype": frm.doc.reference_doctype, - "docname": frm.doc.reference_docname + "bank_guarantee_type": frm.doc.bg_type, + "reference_name": frm.doc.reference_docname }, callback: function(r) { if (r.message) { diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index 9144a29c6e..a57acda680 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -2,11 +2,8 @@ # For license information, please see license.txt -import json - import frappe from frappe import _ -from frappe.desk.search import sanitize_searchfield from frappe.model.document import Document @@ -25,14 +22,17 @@ class BankGuarantee(Document): @frappe.whitelist() -def get_vouchar_detials(column_list, doctype, docname): - column_list = json.loads(column_list) - for col in column_list: - sanitize_searchfield(col) - return frappe.db.sql( - """ select {columns} from `tab{doctype}` where name=%s""".format( - columns=", ".join(column_list), doctype=doctype - ), - docname, - as_dict=1, - )[0] +def get_voucher_details(bank_guarantee_type, reference_name): + fields_to_fetch = ["grand_total"] + + doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order" + + if doctype == "Sales Order": + fields_to_fetch.append("customer") + fields_to_fetch.append("project") + else: + fields_to_fetch.append("supplier") + + bg_doctype = frappe.qb.DocType("Bank Guarantee") + + return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True) From 4b9921782b0427ae4882d186d37fdb960671eed7 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 13 Nov 2022 18:48:32 +0530 Subject: [PATCH 2/3] chore: Remove qb doc reference --- erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index a57acda680..0e3f7d7571 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -33,6 +33,4 @@ def get_voucher_details(bank_guarantee_type, reference_name): else: fields_to_fetch.append("supplier") - bg_doctype = frappe.qb.DocType("Bank Guarantee") - return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True) From b06345af46d8469b46cdf795389a589c58729439 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sun, 13 Nov 2022 19:58:49 +0530 Subject: [PATCH 3/3] fix: check type for reference name --- .../accounts/doctype/bank_guarantee/bank_guarantee.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index 0e3f7d7571..02eb599acc 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -22,15 +22,18 @@ class BankGuarantee(Document): @frappe.whitelist() -def get_voucher_details(bank_guarantee_type, reference_name): +def get_voucher_details(bank_guarantee_type: str, reference_name: str): + if not isinstance(reference_name, str): + raise TypeError("reference_name must be a string") + fields_to_fetch = ["grand_total"] - doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order" - - if doctype == "Sales Order": + if bank_guarantee_type == "Receiving": + doctype = "Sales Order" fields_to_fetch.append("customer") fields_to_fetch.append("project") else: + doctype = "Purchase Order" fields_to_fetch.append("supplier") return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)