Get Contact's primary address

Hey,

I currently the following functions in one of my scripts to fetch the customer contact:
from frappe.contacts.doctype.contact.contact import get_contact_details, get_default_contact

I want something similar but for the default address. I search throughout the contact doctype code and all the forums but couldn’t find anything. Could anyone help me out? I’m completely lost.

To be more specific, I have a custom script that fires upon the on_save event on the Customer doctype. I want to fetch the default/primary address of the Customer open. is there something I can do with cur_frm or is there function in ERPNext that I can whitelist and use or could one of you amazing people help me with some code that would put me in the right direction.

Any help would be greatly appreciated. Thank you for reading this.

I will take a stab at this…

My early work with the early beta v13 erpnext installs I found that “address” had become a completely separate thing and is no longer part of the contact record. At that time, it was merely a link to an address record in a separate table.

This allowed the “Contact” to be saved without an address (and with really very little required information).

Unlike earlier iterations of erpnext, the separation of addresses from everything else seems to be fairly complete in v13 and having one is not necessarily required any longer.

To extrapolate that out a little further, trying to fetch a null value or a completely non-existant value (if no address was recorded) could be problematic.

Again, this is from a long time ago in my experimenting with v13, but I was surprised at how much could be done without an address.

This may or may not have been helpful. Sorry if it was not.

BKM

1 Like

Hey BKM,

First of all, thank you for taking the time out of your day and helping me with this. I really appreciate it.

Second, that information is very interesting and very valuable. From what I understand, theres a separate table for the address information. If only there was some way to access it, I’d just need the Address Line 1, City, State, Country fields.

Is it somehow possible to get that record? I have been at it for a couple of days and still can’t move forward with my project without an address.

Also, I completely forgot to mention that I’m running v12. I didn’t update because my installation was highly customized and I also edited a lot of the source code.

Again, thank you very much for helping me out with this.

Hi BKM, thanks, cleared some things.

How do you link contact with address now that they are separate? In the template for importing I don’t see any link to contacts.

Thanks again

Martín

I think this is solved here: