From 12e7bc025f348f7da5570d4dea769696a96b3063 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 7 Nov 2019 15:23:37 +0530 Subject: [PATCH 1/2] fix: Name of Contact cannot be Contact error while creating communication --- .../doctype/communication/communication.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 2be07cadd2..8e4c5c357d 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -351,16 +351,26 @@ def get_contacts(email_strings): email = get_email_without_link(email) contact_name = get_contact_name(email) - if not contact_name: - contact = frappe.get_doc({ - "doctype": "Contact", - "first_name": frappe.unscrub(email.split("@")[0]), - }) - contact.add_email(email_id=email, is_primary=True) - contact.insert(ignore_permissions=True) - contact_name = contact.name + if not contact_name and email: + email_parts = email.split("@") + first_name = frappe.unscrub(email_parts[0]) - contacts.append(contact_name) + try: + contact = frappe.get_doc({ + "doctype": "Contact", + "first_name": first_name, + }) + contact.add_email(email_id=email, is_primary=True) + contact.name = ('{0}-{1}'.format(first_name, email_parts[1]) + if first_name == 'Contact' else first_name) + contact.insert(ignore_permissions=True) + contact_name = contact.name + except Exception: + traceback = frappe.get_traceback() + frappe.log_error(traceback) + + if contact_name: + contacts.append(contact_name) return contacts From 16f6ba4d2f63ab4c03f78aa3f01df718af7a52c8 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 20 Dec 2019 13:36:09 +0530 Subject: [PATCH 2/2] fix: rename first_name --- frappe/core/doctype/communication/communication.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 8e4c5c357d..5c8983ea22 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -356,13 +356,13 @@ def get_contacts(email_strings): first_name = frappe.unscrub(email_parts[0]) try: + contact_name = '{0}-{1}'.format(first_name, email_parts[1]) if first_name == 'Contact' else first_name contact = frappe.get_doc({ "doctype": "Contact", - "first_name": first_name, + "first_name": contact_name, + "name": contact_name }) contact.add_email(email_id=email, is_primary=True) - contact.name = ('{0}-{1}'.format(first_name, email_parts[1]) - if first_name == 'Contact' else first_name) contact.insert(ignore_permissions=True) contact_name = contact.name except Exception: