From 4e182b89ce66db9bfb97c332c0132c12e6a83b57 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 29 Jan 2024 19:35:05 +0530 Subject: [PATCH] fix: not able to save BOM (duplicate key error) (#39620) --- erpnext/manufacturing/doctype/bom/bom.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index f034ed2b1a..6f3520618b 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -176,8 +176,10 @@ class BOM(WebsiteGenerator): 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: