In past versions of ERPNext items without a naming series could be easily made to have a naming series by creating the custom field naming_series. Once this field was created you could control the naming of that doctype on the Document Naming Settings page.
In version 15 you cannot create the field naming_series, only custom_naming_series, because of the custom prefix that is appended automatically. Due to this it does not appear that you can create naming series for doctypes that don’t come with them.
As a result of this you have to use Customize Form and set a Naming Rule using an expression however Expression also seems to be changing.
When Expression is used you can set format:ABC{####} but the number sequence is shared between all doctypes which doesn’t really replace a naming series.
Expression (old style) does still seem to be able to accomplish a Naming Series unique to a doctype but the naming makes me think that this method may be on its way out.
So I guess my questions are:
Was creating a naming series for doctypes that don’t have one by default removed on purpose or as an oversight?
Is Expression (old style) going to be phased out and if not should its name be changed?
add custom_field.py file under the override folder and paste the code:
import frappe
from frappe import _
from frappe.utils import cstr, random_string
from frappe.custom.doctype.custom_field.custom_field import CustomField
class CustomFieldOverride(CustomField):
def set_fieldname(self):
restricted = (
"name",
"parent",
"creation",
"modified",
"modified_by",
"parentfield",
"parenttype",
"file_list",
"flags",
"docstatus",
)
if not self.fieldname:
label = self.label
if not label:
if self.fieldtype in ["Section Break", "Column Break", "Tab Break"]:
label = self.fieldtype + "_" + str(random_string(5))
else:
frappe.throw(_("Label is mandatory"))
# remove special characters from fieldname
self.fieldname = "".join(
[c for c in cstr(label).replace(" ", "_") if c.isdigit() or c.isalpha() or c == "_"]
)
# fieldnames should be lowercase
self.fieldname = self.fieldname.lower()
if self.fieldname in restricted:
self.fieldname = self.fieldname + "1"
Then restart the bench.
When you make a new custom field, the word “custom” won’t be automatically added to it. Instead, you can use “naming_series” as your custom field.
old style one will be around for a long time. naming series field and old style expression are essentially same.
“format:” style will be deprecated over time.
This us somewhat misleading but old/new style are basically same except that “format:” style is not really usable because of it’s shared counter implementation.