75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
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) {
|
|
// 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 defaults you don't want
|
|
frm.toggle_display("customer_group", false);
|
|
|
|
// Required fields
|
|
frm.set_df_property("mobile_no", "reqd", 1);
|
|
|
|
// Defaults
|
|
frm.set_value("territory", "United States");
|
|
|
|
// Add Company fields to Quick Entry
|
|
frm.add_custom_field({
|
|
fieldname: "company_name",
|
|
label: "Company Name",
|
|
fieldtype: "Data",
|
|
insert_after: "customer_name",
|
|
reqd: 1
|
|
});
|
|
},
|
|
|
|
// ZIP auto-fill
|
|
pincode(frm) {
|
|
if (!frm.is_quick_entry) return;
|
|
|
|
const zip = frm.doc.pincode;
|
|
if (!zip || zip.length < 5) return;
|
|
|
|
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?.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(() => {});
|
|
}
|
|
});
|