Customer Doctype, autoname issue with possible fix

Hey Team!

So I noticed that If I added customers with the same name the autoname method on the customer doctype would only auto name my customers correctly up to 10 records. After that I would get duplicate id error stating I already had a customer ending in " - 10"

This is with a clean erpnext installation

I am not sure if this is by design but I have a possible fix:

FROM erpnext/selling/doctype/customer/ LINE 55:

count = frappe.db.sql("""select ifnull(MAX(SUBSTRING_INDEX(name, ' ', -1)), 0) from tabCustomer where name like %s""", "%{0} - %".format(self.customer_name), as_list=1)[0][0]

TO: MAX works best with numbers not strings

count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) as UNSIGNED)), 0) from tabCustomer where name like %s order by length(name) desc, name desc limit 1""", "%{0} - %".format(self.customer_name), as_list=1)[0][0]

This fix give me the correct customer name series past 10, but I am unsure if this is a bug or design to stop adding customers past 10 series.



@Felipe_Orellana seems like an oversight, pls send a PR

Ah, no problem @rmehta I’ve submitted a pull request here: