I want to have a custom naming series for the Assets in the ERPNext system. Currently what I want is to have the Item Code in the first place and separated by a dash and then a 6 digit number series. For Example FF00303-009679. But I want the number series to start from 009678, instead of “000001”.
Eg: Item Code = FF00303, OE0210 etc…
Example:
FF0305-009678
OE0210-009679
LT0830-009680
For far I was able to set the Item code with a dash and a number series(but starts from “000001”), I’m struggling to set the number series to start from 009678.
I have written it as .{item_code}.-.#####
In the Update series counter, I have set the prefix to blank and current value as 009677 but it doesn’t start from 009677, instead it starts from 000001.
It does work properly by default. I want to customize it to have a fixed number series at the end which is not relative to the Item code, and it should start with 009668.
Below are the changes that I’ve made in the Document Naming Settings,
The issue is that I want the series to continue in the below format, So a fixed prefix can’t be set for my use case.
.{item_code).-009668
Prefix = .{item_code}.
Number Series to start from = 009668
Example:
FF0305-009669
OE0210-009670
LT0830-009671
Prefix should be the item code, and it cannot be hard-coded, since the Item code can vary according to the item. Is there are any method, to set the prefix as a variable and number series to start from 009668?
Tried writing a custom script, but didn’t managed to get it working, since it interfere with the Document Naming settings and the Old Document Naming settings. Tried clearing bench cache too, but wasn’t able get it working. Below is the server script that I wrote,
def set_global_asset_naming_series(doc, method):
# Define a global series pattern to manage the numbering
global_series_pattern = "GLOBAL-ASSET"
# Fetch the current series value for the global pattern
current_series = frappe.db.sql("""
SELECT current FROM `tabSeries` WHERE name = %s
""", (global_series_pattern))
# If the series doesn't exist, initialize it at 009677 so the next one will be 009678
if not current_series:
frappe.db.sql("""
INSERT INTO `tabSeries` (name, current)
VALUES (%s, %s)
""", (global_series_pattern, 9677))
new_series_number = 9677
else:
# Update the global series counter (incrementing it for the next asset)
frappe.db.sql("""
UPDATE `tabSeries` SET current = current + 1 WHERE name = %s
""", (global_series_pattern))
# Fetch the updated series number
new_series_number = frappe.db.sql("""
SELECT current FROM `tabSeries` WHERE name = %s
""", (global_series_pattern))[0][0]
# Construct the new asset ID with the Item Code and global series number
new_asset_id = f"{doc.item_code}-{str(new_series_number).zfill(6)}"
# Check for duplicate asset ID
if frappe.db.exists("Asset", new_asset_id):
frappe.throw(f"Duplicate Asset ID: {new_asset_id} already exists")
# Set the Asset Name with the global series number
doc.name = new_asset_id
Any suggestions for a workaround ? Is there any way to set the number series global and not relative to the item code ?
I think currently the custom Script is getting interfered with the Document naming Settings ? is there any way to avoid it, I tried leaving the “Series List for this Transaction” field empty, but it displays that it cannot be left empty. Is there any method to override the default Document Naming Settings using a custom script or any other method ?