Pull Custom Field into Naming Series

Hi,

I wonder how I in a Naming Series can retrieve the value from a custom field (or other good solutions to the below example).

I prefer to have a short-code for suppliers, i.e. WN for company “Web Notes” that can later be used on documents for quick identication.

  • Added custom field “Vendor ID” to Document: Supplier.
  • Then under Naming Series, I want something like
    • PO-.YY.MM.-.{vendor_id}.-.#####
    • Resulting in “PO-1503-WN-00001”

Let me know best approach and related:

  • how a custom field can be
  • validated for uniquness
  • attaching a small script to auto-create & populate (in this case) the “vendor id” shortcode based off say the company name.

Thanks
David

This is not a feature yet,

but you pass doc and can fix his here:

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.

thanks david

@raveslave this seems like a good update, you can add it and send a pull-request, we will add it in the product.

Add your custom validations in the validate or before_save hook.

Added Enable Custom Fields in Naming Series Enable Custom Fields in Naming Series · Issue #3019 · frappe/erpnext · GitHub

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.

maybe there are ways to do this already?

Company master does have an abbreviation field, what are other use cases?

We are currently pretty much tied up in version 5 release… Lets get back to this after a couple of weeks.

Has ERPNext been able to get to this? The customization of naming series improves usability tremendously from end users perspective.

Also very interested in this.

Hi @kirthi and @superlack

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.

regards
Hemant

2 Likes