Autofill on ZIP for Customer Quick Entry changes
This commit is contained in:
@@ -29,45 +29,46 @@ frappe.ui.form.on("Customer", {
|
||||
onload(frm) {
|
||||
if (!frm.is_quick_entry) return;
|
||||
|
||||
console.log("NS App: Modifying Quick Entry Fields");
|
||||
console.log("NS App: Enhancing Customer Quick Entry");
|
||||
|
||||
// Hide unwanted fields
|
||||
// Hide defaults you don't want
|
||||
frm.toggle_display("customer_group", false);
|
||||
|
||||
// Make fields required
|
||||
// Required fields
|
||||
frm.set_df_property("mobile_no", "reqd", 1);
|
||||
|
||||
// Defaults
|
||||
frm.set_value("territory", "United States");
|
||||
|
||||
// Add Owner 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 (kept from previous step)
|
||||
pincode(frm) {
|
||||
if (!frm.is_quick_entry) return;
|
||||
|
||||
const zip = frm.doc.pincode;
|
||||
if (!zip || zip.length < 5) return;
|
||||
|
||||
// Optional: only run for US
|
||||
if (frm.doc.country && frm.doc.country !== "United States") return;
|
||||
|
||||
fetch(`https://api.zippopotam.us/us/${zip}`)
|
||||
.then(res => {
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
})
|
||||
.then(res => res.ok ? res.json() : null)
|
||||
.then(data => {
|
||||
if (!data || !data.places || !data.places.length) return;
|
||||
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);
|
||||
|
||||
console.log("NS App: ZIP auto-filled address", data);
|
||||
})
|
||||
.catch(() => {
|
||||
console.log("Invaild Zip!")
|
||||
});
|
||||
.catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user