chore: Remove raw SQL query

This commit is contained in:
Deepesh Garg 2022-11-12 17:32:04 +05:30
parent 5f1b226362
commit 42a59d5c17
2 changed files with 17 additions and 24 deletions

View File

@ -43,20 +43,13 @@ frappe.ui.form.on('Bank Guarantee', {
reference_docname: function(frm) { reference_docname: function(frm) {
if (frm.doc.reference_docname && frm.doc.reference_doctype) { 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"; 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({ 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: { args: {
"column_list": fields_to_fetch, "bank_guarantee_type": frm.doc.bg_type,
"doctype": frm.doc.reference_doctype, "reference_name": frm.doc.reference_docname
"docname": frm.doc.reference_docname
}, },
callback: function(r) { callback: function(r) {
if (r.message) { if (r.message) {

View File

@ -2,11 +2,8 @@
# For license information, please see license.txt # For license information, please see license.txt
import json
import frappe import frappe
from frappe import _ from frappe import _
from frappe.desk.search import sanitize_searchfield
from frappe.model.document import Document from frappe.model.document import Document
@ -25,14 +22,17 @@ class BankGuarantee(Document):
@frappe.whitelist() @frappe.whitelist()
def get_vouchar_detials(column_list, doctype, docname): def get_voucher_details(bank_guarantee_type, reference_name):
column_list = json.loads(column_list) fields_to_fetch = ["grand_total"]
for col in column_list:
sanitize_searchfield(col) doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order"
return frappe.db.sql(
""" select {columns} from `tab{doctype}` where name=%s""".format( if doctype == "Sales Order":
columns=", ".join(column_list), doctype=doctype fields_to_fetch.append("customer")
), fields_to_fetch.append("project")
docname, else:
as_dict=1, fields_to_fetch.append("supplier")
)[0]
bg_doctype = frappe.qb.DocType("Bank Guarantee")
return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)