thanks. what’s the best approach patching in mini-features like this without risking breaking things and/or running into trouble upon pulling future updates?
also, (even though a bit unrelated to naming series) can a custom field have a pre-save hook that can validate a value for uniquness, i.e. a serial, or an abbreviation!?
…and upon “render” run a script/filter to pre-populate a custom field accordingly.
Need some guidance on best approach for how to deal with macros for “Custom Fields”.
Some example use-cases:
Abbreviations
A configurable abbreviation utility that can be used system-wide.
Fields should be configurable to automatically be populated with a two or three-letter abbreviation based off another field (company name → company code)
Result should be tested for uniqueness and allow for manual override.
Data-driven
Pre-populate a field from list-data,
i.e. a pre-generated set of serial-numbers, voucher-codes, etc.
“REST field”, like above but pull next unique from an external system
this could be from a PLM that generates a new part-number for a component.
or a bar-code system that generates a unique label and returns the vaule.
I managed to get this to work by created in ‘before_save’ and added a {customfield} on the doc then changed the 'Naming>Auto Name" on the doc to "field:{customfield}
On the hook write the code you need to get the code you need it to be and pass the doc back.
Hope this helps - sorry im still a noob when it comes to erpnext so if others have a better solutions please add.
Im concerned about this solution as I hope it wont break anything when doing updates from main branch.
—Update---- looks like you dont need to even add a field, still dont know how to get the “field” feature working in erpnext but for now I updated with just creating a hook “before_save” and do my customer series there and update doc.name there. No need to customise the doc. with this I can also create a single series py file that can be used to other doctypes.