fix: not able to save BOM (duplicate key error) (#39620)
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index f034ed2..6f35206 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -176,8 +176,10 @@
def autoname(self):
# ignore amended documents while calculating current index
+
+ search_key = f"{self.doctype}-{self.item}%"
existing_boms = frappe.get_all(
- "BOM", filters={"item": self.item, "amended_from": ["is", "not set"]}, pluck="name"
+ "BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name"
)
if existing_boms: