Using the Address DocType in Custom Frappe App

  1. Create a Link field to Address DocType primary_address
  2. Create a HTML field type and use Name : address_html (The field name has to be address_html or it will not work as intended.)
  3. Check if file is not saved then use in JS:
if(!frm.doc.__islocal) {
  frappe.contacts.render_address_and_contact(frm);
    } else {
  frappe.contacts.clear_address_and_contact(frm);
}
  1. To filter address list by selected user, use in JS:
frm.set_query('primary_address', function(doc) {
  return {
  	filters: {
    'link_doctype': 'DocType',
    'link_name': doc.name
  	}
  }
})
  1. In .py file use:
def onload(self):
  """Load address and contacts in `__onload`"""
  load_address_and_contact(self)
  1. To delete address on deleting entry:
def on_trash(self):
  delete_contact_and_address("Member", self.name)
  1. Imports required:
from frappe.contacts.address_and_contact import (
	delete_contact_and_address,
	load_address_and_contact,
)