How to change separator symbol used for contact and company name

I am a user of ERPNext with no real experience developing it. One of the things I find irritating as a user is the automatic addition of a hyphen “-” followed by the company name to contact names whenever they are linked to a customer record. For example, If I create a Contact called “Jo Bloggs” and link to the Customer “Bloggs Inc” the contact is listed as “Jo Bloggs-Blogs Inc”.

In many instances the hyphen can look cumbersome and make reading the name difficult. Instead using a vertical bar separated by spaces " | " might be better, eg, “Jo Bloggs | Blogs Inc”.

How could I customise ERPNext so that the vertical bar symbol is automatically used instead of the hyphen?

Hi @samlivingstone,

That hyphen separator is hard-coded in the document controller for Contact.

  • File: …/apps/frappe/frappe/doctype/contact/contact.py
  • Document method autoname()

Screenshot below.

To substitute a vertical bar, you’d have to alter this function. Either directly, or by patching it.

P.S. I’m also not a fan of this naming convention for contacts.

3 Likes

In your custom app, override the doc_events in hooks.py for doctype “Contact” Hooks

# hooks.py
doc_events = {
 	"Contact": {
 		"autoname": "path.to.overridden.autoname",
	}
}

# overridden.py
import uuid


def autoname(self, method=None):
        self.name = str(uuid.uuid4()) # Use this to set uuid4 string 
        # OR copy code from Contact.autoname with replacement
        # Also pass `separator` to append_number_if_name_exists('Contact, self.name, separator=' | ')
2 Likes

Thanks for these solutions. I’ll give them a go!

Is there a way to have them be persistent even after version updates? Or would I need to change the code each time?

Either way, your changes will be persistent.