Custom name attribute for customers

Hi,

anyone know how to disable autoname when creating a doc from a script?

I’m working on a application that will get customers from another system. All my customers have a unique ID but their customer_name can change from time to time. Name should not change once customer created.

I would like to name them “CUST-FROM-OTHER-SYS-64646” where 64646 is the unique ID of the customer. Please note that is not a naming serie. Customer_name will be something like their company name.
the following code is not working:

cust.name = "CUST-FROM-OTHER-SYS-64646"
cust.save()

I think it is because of autoname feature. How can I bypass it my app? But I want to keep autoname feature for all manually entered customers.

You should be able to disable naming series for customers in the selling settings:

Then, you can set the name on insert (at worst, first set customer_name = your code, insert, then update with the actual customer_name).

Hope this helps…

the two available settings for “customer named by” in selling/settings has been tested :

  • customer name
    is unusable since I can not set cu.name before saving. It 's always overwrited by autoname feature. cu.name is ignored
  • naming series.
    I can set a cu.naming_series= “CUST-FROM-OTHER-SYS-” and when I save I get something like “CUST-FROM-OTHER-SYS-0001”. it’s a custom naming series !:slight_smile: cu.name is ignored

I’ve found no good setting for a custom name for my customers.

I do not see how I can give the right for my app to give a custom name to customers.

You can use autoname() function.

thanks @bhavikpatel7023, you drived me the good way.
Get it working with doc_events. Maybe some newbies like me will be happy to find my simple tuto.

in the app, hook.py file:

doc_events = {
 	"Customer": {
 		"autoname": "myapp.mycustomer.name_customer",
	}
}

in mycustomer.py module:

def name_customer(doc, method):
    if doc.my_own_id:
        doc.name = "CUST-FROM-MYAPP-{}".format(doc.my_own_id)

name_customer() will be always called each time a new Customer is inserted, not only when Customer is created from my own app. The “doc.my_own_id” attribute is used to apply the custom name only for Customers created from my own app. For other Customers the erpnext autoname method will do its job.

the method called by hooks_events takes two parameters: doc is the doc, method is the method name (here it is autoname)

oh! and it is not depending on selling settings option.

full doc :
https://frappe.io/docs/user/en/guides/basics/hooks#crud-events

2 Likes