Merge pull request #50962 from rohitwaghchaure/fixed-github-50829

fix: warning message to avoid serial no series overlap issue
This commit is contained in:
rohitwaghchaure
2025-12-08 14:40:10 +05:30
committed by GitHub
2 changed files with 31 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import json
import frappe
from frappe import _, bold
from frappe.model.document import Document
from frappe.model.naming import NamingSeries
from frappe.query_builder import Interval
from frappe.query_builder.functions import Count, CurDate, UnixTimestamp
from frappe.utils import (
@@ -409,6 +410,24 @@ class Item(Document):
)
)
if self.is_new() and series:
obj = NamingSeries(series)
prefix = obj.get_prefix()
doctype = frappe.qb.DocType("Series")
query = frappe.qb.from_(doctype).select(doctype.name).where(doctype.name.like(f"{prefix}%"))
prefix_exists = query.run(as_dict=True)
if prefix_exists:
frappe.msgprint(
_(
"The {0} prefix '{1}' already exists. Please change the Serial No Series, otherwise you will get a Duplicate Entry error."
).format(bold(frappe.unscrub(field)), bold(prefix)),
title=_("Serial No Series Overlap"),
indicator="yellow",
alert=True,
)
def check_for_active_boms(self):
if self.default_bom:
bom_item = frappe.db.get_value("BOM", self.default_bom, "item")

View File

@@ -1432,7 +1432,18 @@ class SerialBatchCreation:
"batch_no",
]
frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details))
try:
frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details))
except Exception as e:
if e and len(e.args) > 1 and "Duplicate" in e.args[1]:
frappe.throw(
_(
"A naming series conflict occurred while creating serial numbers. Please change the naming series for the item {0}."
).format(bold(self.item_code)),
title=_("Duplicate Serial Number Error"),
)
else:
raise e
obj.update_counter(current_value)