Merge pull request #8775 from rohitwaghchaure/email_not_pull_because_of_contact_error
fix: Name of Contact cannot be Contact error while creating communication for incoming emails
This commit is contained in:
commit
3ba9c2dfd4
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_name = '{0}-{1}'.format(first_name, email_parts[1]) if first_name == 'Contact' else first_name
|
||||
contact = frappe.get_doc({
|
||||
"doctype": "Contact",
|
||||
"first_name": contact_name,
|
||||
"name": contact_name
|
||||
})
|
||||
contact.add_email(email_id=email, is_primary=True)
|
||||
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