Skip to content

Commit

Permalink
fix: ignore duplicate contact creation (#23423) (#23730)
Browse files Browse the repository at this point in the history
(cherry picked from commit ddac8af)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
  • Loading branch information
mergify[bot] and nabinhait committed Dec 11, 2023
1 parent 045d059 commit cd50875
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions frappe/core/doctype/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,27 +1227,31 @@ def create_contact(user, ignore_links=False, ignore_mandatory=False):

contact_name = get_contact_name(user.email)
if not contact_name:
contact = frappe.get_doc(
{
"doctype": "Contact",
"first_name": user.first_name,
"last_name": user.last_name,
"user": user.name,
"gender": user.gender,
}
)
try:
contact = frappe.get_doc(
{
"doctype": "Contact",
"first_name": user.first_name,
"last_name": user.last_name,
"user": user.name,
"gender": user.gender,
}
)

if user.email:
contact.add_email(user.email, is_primary=True)
if user.email:
contact.add_email(user.email, is_primary=True)

if user.phone:
contact.add_phone(user.phone, is_primary_phone=True)
if user.phone:
contact.add_phone(user.phone, is_primary_phone=True)

if user.mobile_no:
contact.add_phone(user.mobile_no, is_primary_mobile_no=True)
contact.insert(
ignore_permissions=True, ignore_links=ignore_links, ignore_mandatory=ignore_mandatory
)
if user.mobile_no:
contact.add_phone(user.mobile_no, is_primary_mobile_no=True)

contact.insert(
ignore_permissions=True, ignore_links=ignore_links, ignore_mandatory=ignore_mandatory
)
except frappe.DuplicateEntryError:
pass
else:
contact = frappe.get_doc("Contact", contact_name)
contact.first_name = user.first_name
Expand Down

0 comments on commit cd50875

Please sign in to comment.