diff --git a/frappe/contacts/doctype/address/address.py b/frappe/contacts/doctype/address/address.py index c5de5706a8..c09f6a0c59 100644 --- a/frappe/contacts/doctype/address/address.py +++ b/frappe/contacts/doctype/address/address.py @@ -57,14 +57,10 @@ class Address(Document): def set_link_title(self): if not self.links: return - else: - for address in self.links: - if not address.link_title: - linked_doc = frappe.get_doc(address.link_doctype, address.link_name) - try: - address.link_title = linked_doc.title_field - except AttributeError: - address.link_title = linked_doc.name + for address in self.links: + if not address.link_title: + linked_doc = frappe.get_doc(address.link_doctype, address.link_name) + address.link_title = linked_doc.get("title_field") or linked_doc.get("name") def validate_reference(self): if self.is_your_company_address: diff --git a/frappe/contacts/doctype/contact/contact.py b/frappe/contacts/doctype/contact/contact.py index 82e2258bd5..3cd98c57e5 100644 --- a/frappe/contacts/doctype/contact/contact.py +++ b/frappe/contacts/doctype/contact/contact.py @@ -44,14 +44,10 @@ class Contact(Document): def set_link_title(self): if not self.links: return - else: - for contact in self.links: - if not contact.link_title: - linked_doc = frappe.get_doc(contact.link_doctype, contact.link_name) - try: - contact.link_title = linked_doc.title_field - except AttributeError: - contact.link_title = linked_doc.name + for contact in self.links: + if not contact.link_title: + linked_doc = frappe.get_doc(contact.link_doctype, contact.link_name) + contact.link_title = linked_doc.get("title_field") or linked_doc.get("name") def get_link_for(self, link_doctype): '''Return the link name, if exists for the given link DocType'''