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:
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 ! 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.
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.