diff --git a/frappe/boot.py b/frappe/boot.py index 040c695773..9c8bd43f60 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -109,6 +109,9 @@ def get_bootinfo(): bootinfo.subscription_conf = add_subscription_conf() bootinfo.marketplace_apps = get_marketplace_apps() bootinfo.changelog_feed = get_changelog_feed_items() + bootinfo.address_autocomplete_enabled = frappe.db.get_single_value( + "Address Autocomplete Settings", "enabled" + ) return bootinfo diff --git a/frappe/public/js/frappe/utils/address_and_contact.js b/frappe/public/js/frappe/utils/address_and_contact.js index 1cea4d1514..14ac101049 100644 --- a/frappe/public/js/frappe/utils/address_and_contact.js +++ b/frappe/public/js/frappe/utils/address_and_contact.js @@ -12,7 +12,7 @@ $.extend(frappe.contacts, { $(frm.fields_dict["address_html"].wrapper) .html(frappe.render_template("address_list", frm.doc.__onload)) .find(".btn-address") - .on("click", () => new_record("Address", frm.doc)); + .on("click", () => new_record("Address", frm)); } // render contact @@ -20,7 +20,7 @@ $.extend(frappe.contacts, { $(frm.fields_dict["contact_html"].wrapper) .html(frappe.render_template("contact_list", frm.doc.__onload)) .find(".btn-contact") - .on("click", () => new_record("Contact", frm.doc)); + .on("click", () => new_record("Contact", frm)); } }, get_last_doc: function (frm) { @@ -59,12 +59,23 @@ $.extend(frappe.contacts, { }, }); -function new_record(doctype, source_doc) { +function new_record(doctype, frm) { frappe.dynamic_link = { - doctype: source_doc.doctype, - doc: source_doc, + doctype: frm.doc.doctype, + doc: frm.doc, fieldname: "name", }; - return frappe.new_doc(doctype); + if (frappe.boot.address_autocomplete_enabled === 1 && doctype === "Address") { + new frappe.ui.AddressAutocompleteDialog({ + title: __("New Address"), + link_doctype: frm.doc.doctype, + link_name: frm.doc.name, + after_insert: function (doc) { + frm.reload_doc(); + }, + }).show(); + } else { + frappe.new_doc(doctype); + } }