diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index c3105b8e9eca..f8523c889330 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -176,9 +176,14 @@ def autoname(self): search_key = f"{self.doctype}-{self.item}%" existing_boms = frappe.get_all( - "BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name" + "BOM", filters={"name": search_key, "amended_from": ["is", "not set"]}, pluck="name" ) + if not existing_boms: + existing_boms = frappe.get_all( + "BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name" + ) + if existing_boms: index = self.get_next_version_index(existing_boms) else: