Fetch address details to custom fields on sales invoice

To simplify an export of invoice data to our accounting package I want to fetch the various address fields stored against the customer record to custom fields on my Sales Invoice doc type. I’ve setup a Sales Invoice custom field with the same name of “address_line1” and created a custom script for Sales Invoice of:

cur_frm.add_fetch("Address", {"customer": doc.customer}, "address_line1")

But the address line does not populate in the Sales Invoice. I have tried setting that field to read_only and back with no change.

Can anyone help me with this please?

Thanks
Liam.

I don’t think add fetch works that way

cur_frm.add_fetch("customer", "address_line1", "address_line1")

Will that work though @rmehta given the customer doc type doesn’t hold the address? When fetching the phone field from Address doc type in a custom print I’ve used this successfully:

{{ frappe.db.get_value("Address", {"customer": doc.customer}, "phone") }}

So that was what I was based my logic above on. I need to lookup to Address doc type which is linked to customer doc type and fetch the address_line1, etc. Does that make sense?

Your statement assumes address details are against Customer doc type when they aren’t?

I tried your statement with both read only on and off on my Sales Invoice “Address_line1” field and it didn’t work unfortunately.

Cheers.

This is my setup, please check for errors: Thanks.