frappe.ready(() => { const original_make_quick_entry = frappe.ui.form.make_quick_entry; frappe.ui.form.make_quick_entry = function (doctype, after_insert, init_callback) { if (doctype !== "Customer") { return original_make_quick_entry.apply(this, arguments); } console.log("NS App: Custom Customer Quick Entry Loaded"); return original_make_quick_entry.call( this, doctype, after_insert, function (doc) { // Safe defaults doc.customer_group = "Commercial"; doc.territory = "United States"; if (init_callback) { init_callback(doc); } } ); }; }); frappe.ui.form.on("Customer", { onload(frm) { if (!frm.is_quick_entry) return; console.log("NS App: Enhancing Customer Quick Entry"); // Hide fields you don't want exposed frm.toggle_display("customer_group", false); // Make required frm.set_df_property("mobile_no", "reqd", 1); // Default territory frm.set_value("territory", "United States"); /** * IMPORTANT: * "company_name" MUST already exist as a Custom Field in erpnext * (Customer → Custom Fields) */ frm.toggle_display("company_name", true); // Company name is OPTIONAL by default frm.set_df_property("company_name", "reqd", 0); }, /** * ZIP auto-fill * NOTE: This only works if pincode/city/state/country * are available in Quick Entry (customized Address block) */ pincode(frm) { if (!frm.is_quick_entry) return; const zip = frm.doc.pincode; if (!zip || zip.length < 5) return; // Only US ZIPs if (frm.doc.country && frm.doc.country !== "United States") return; fetch(`https://api.zippopotam.us/us/${zip}`) .then(res => res.ok ? res.json() : null) .then(data => { if (!data || !data.places || !data.places.length) return; const place = data.places[0]; frm.set_value("city", place["place name"]); frm.set_value("state", place["state"]); frm.set_value("country", data.country); }) .catch(() => { // Fail silently (never block entry) }); } });