erpnext
erpnext copied to clipboard
[v13] Multiple customer getting created for same user.
Set Customer
as the default role of user on signup from Portal Settings
.
On every subsequent login of the same user, new customers are created with - n
in the end.
Also gets a msgprint saying customer name was changed to the newly created one cause there exists an entry with the same name.
For example, on first login, a customer named Dany
will be created. Now if I log out and log in again, Dany - 1
will be created.
ERPNext: v13.2.0 (version-13) Frappe Framework: v13.2.0 (version-13)
This seems to be fixed. Closing the issue.
In Which Version it got Solved?
In Which Version it got Solved?
I'm unsure, are you facing similar issue?
yes in , erpnext 13.4.0 frappe 13.4.1
Experience the same issue in v13, would like to know the snippet where it gets fixed.
Reopening this due to above comments. Unverified from my side on the latest version tho.
Similar issue #31845 @ankush
I've run into this before. I remember the User ID field and the primary email address in Contact have to be the same. If the emails are different then a new Customer will get created.
I verified and here is how to recreate the bug on my end:
- User ID and Primary Email are the same in Contact
- User has only one role Customer
- In Portal Settings, Default Role at Time of Signup is set to Customer
- Log in and out several times
- A new customer is created every time the user logs in.
ERPNext 13.36.5 Frappe 13.39.1
Hello,
I have been able to locate and fix the issue, but I am not sure if it is a proper solution. I don't know how to contribute the solution to the repository so I'll post it here.
Anyways here's how it goes:
First, the issue was in the file erpnext/erpnext/portal/utils.py
The first issue was that when verifying for party exists, it was looking for the party in Contacts
using the user email address first then it runs another condition and looks if the Contact has a doctype linked to it with the user's full name.
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]
return doctype in doctypes
return False
Since this code will return false anyways then it creates a new customer/supplier. The code to fix it as below:
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]
if doctype in doctypes:
return True
else:
contact.append("links", dict(link_doctype=doctype, link_name=contact_name))
contact.flags.ignore_mandatory = True
contact.save(ignore_permissions=True)
return True
# return doctype in doctypes
return False
After creating the customer/supplier then it goes to create a contact for it and here is the second issue; when creating a new contact it forgets to mark the email address in the (Email IDs) table as primary so that it is populated in the (Email Address/email_id) field of the doc, thus resulting in creating a duplicate contact again and again and again.
The bugged code:
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("email_ids", dict(email_id=user))
contact.flags.ignore_mandatory = True
contact.insert(ignore_permissions=True)
The fix:
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("email_ids", dict(email_id=user, is_primary=1))
contact.flags.ignore_mandatory = True
contact.insert(ignore_permissions=True)
I have been able to locate and fix the issue, but I am not sure if it is a proper solution. I don't know how to contribute the solution to the repository so I'll post it here.
Fork the repo, clone/pull the fork in your bench, make a new branch and switch to it, make the said changes in the code and open a PR! :heart:
Hello,
We can't solve the problem in version 13 because it's not supported anymore. However, it's working fine in version 15, but there's an issue in version 14. If you want, you can try it out in version 15.
Thank You!
I have the same problem in version 15