In this particular example we are fetching the bank details on the basis of IFSC code. There are two doctypes Bank Details IFSC and Av Production
frappe.ui.form.on('Av Production', {
ifsc_code: function(frm) {
frappe.call({
method: "frappe.production_houses.doctype.av_production.api.get",
args: {
doctype:"Bank Details IFSC",
name:frm.doc.ifsc_code,
},
callback: (r) => {
if(r.message) {
frm.set_value('micr',r.message.micr)
frm.set_value('branch_address',r.message.branch_address)
frm.set_value('bank_name', r.message.bank_name)
frm.set_value('branch',r.message.branch)
}
}
});
},
});
…
API.py file
import json
from os import name
import frappe
from frappe import _
from frappe.model.base_document import DOCTYPE_TABLE_FIELDS
from frappe.model.db_query import check_parent_permission
from frappe.query_builder.utils import DocType
@frappe.whitelist()
def get(doctype, name=None ,filters=None, parent=None):
if frappe.is_table(doctype):
check_parent_permission(parent, doctype)
if filters and not name:
name = frappe.db.get_value(doctype, json.loads(filters))
if not name:
frappe.throw(_("No document found for given filters"))
doc = frappe.get_doc(doctype, name)
if not doc.has_permission("read"):
raise frappe.PermissionError
return frappe.get_doc(doctype, name).as_dict()