fix: Name of Contact cannot be Contact error while creating communication
This commit is contained in:
parent
ebeee12326
commit
12e7bc025f
1 changed files with 19 additions and 9 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue