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) {
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) {

View File

@ -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)