Sometimes the naming series options just aren’t that great. I wanted to bring some of the specific variables from the record into the title. Here’s what I came up with:
The is a slight bug on the function.
You need to dd an extra parameter because on event it passes 2 events.
The second parameter is just the event name.
Like a JS event trigger ("onload", "validate" etc)? Those guys? This is (intended to be) python, I have no idea if it’ll run on the client side. Can you share your error? I’ve never had to pass before_insert a trigger before, but something may have changed.
I am trying to make a customized naming series that uses a select field as part of the naming series for the document. My initial step towards even getting a simple custom defined naming series have not worked.
I followed this post and this one regarding customized naming and have come up empty on even getting the first step of getting the hooks and python file to set a field value. Some of my initial problems were related to having the “custom” button checked in the Doctype editor. That seemed to make the Doctype ignore the python file altogether.
My hooks.py file calls my Doctype “Document” in the document events section of the hooks file:
Try running this with you doc_events in hooks commented out.
Also, naming your python method autoname will trigger it at the right time (before_insert).
def autoname(self):
if self.document_number:
self.name = make_autoname(self.document_number + '-.#####')
I commented out doc_events, played with different hooks calls and tried tmatteson’s function below without success.
def autoname(self):
if self.document_number:
self.name = make_autoname(self.document_number + '-.#####')
This is really stumping me. I created a brand new blank DocType to eliminate any other potential script conflicts to test that. @tmatteson, are you successfully using this autoname feature?
Thank you for that reference code. I went line by line through the RestaurantTable.py code, the Doctype layouts, Doctype setups and confirmed that it works as intended. There is something in my custom app that seems to be preventing the autoname function from working. I am going to create a new droplet and see if autoname works in a fresh app environment and start tracing the problem from the ground up.
If you’re in developer mode it should pick the changes right up. It you’re in production mode, bench restart should work (but you should reconsider your dev workflow if you’re developing in production mode).
Eureka! Thank you @tmatteson. I owe you a case of New Hampshire’s finest brew. I was reloading the site in production mode instead of restarting the bench. Hard lesson learned but hopefully someone else will benefit from my wasted weekend struggling with this problem. Everything works even better than I had hoped since the autoname function tracks the numeric sequence for all my unique prefixes.
In full disclosure, I only know about this because I’ve made the same frustrating mistake.
I’ll still take your charity though: join the ERPNext Foundation if you haven’t already.