From 3994aa8b06d67c56cb634c54c8079901570904e6 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 22 Jul 2020 19:49:54 +0530 Subject: [PATCH] fix: Same Contact name for different parties at Portal Login (#22715) --- erpnext/portal/utils.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/erpnext/portal/utils.py b/erpnext/portal/utils.py index 56e4fcde73..d6d4469420 100644 --- a/erpnext/portal/utils.py +++ b/erpnext/portal/utils.py @@ -88,21 +88,30 @@ def create_customer_or_supplier(): party.flags.ignore_mandatory = True party.insert(ignore_permissions=True) + alternate_doctype = "Customer" if doctype == "Supplier" else "Supplier" + + if party_exists(alternate_doctype, user): + # if user is both customer and supplier, alter fullname to avoid contact name duplication + fullname += "-" + doctype + + create_party_contact(doctype, fullname, user, party.name) + + return party + +def create_party_contact(doctype, fullname, user, party_name): contact = frappe.new_doc("Contact") contact.update({ "first_name": fullname, "email_id": user }) - contact.append('links', dict(link_doctype=doctype, link_name=party.name)) + contact.append('links', dict(link_doctype=doctype, link_name=party_name)) + contact.append('email_ids', dict(email_id=user)) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) - return party - - def party_exists(doctype, user): + # check if contact exists against party and if it is linked to the doctype contact_name = frappe.db.get_value("Contact", {"email_id": user}) - if contact_name: contact = frappe.get_doc('Contact', contact_name) doctypes = [d.link_doctype for d in contact.links]