@@ -179,15 +179,7 @@ def autoname(self):
179
179
"BOM" , filters = {"name" : search_key , "amended_from" : ["is" , "not set" ]}, pluck = "name"
180
180
)
181
181
182
- if not existing_boms :
183
- existing_boms = frappe .get_all (
184
- "BOM" , filters = {"name" : ("like" , search_key ), "amended_from" : ["is" , "not set" ]}, pluck = "name"
185
- )
186
-
187
- if existing_boms :
188
- index = self .get_next_version_index (existing_boms )
189
- else :
190
- index = 1
182
+ index = self .get_index_for_bom (existing_boms )
191
183
192
184
prefix = self .doctype
193
185
suffix = "%.3i" % index # convert index to string (1 -> "001")
@@ -205,21 +197,23 @@ def autoname(self):
205
197
name = f"{ prefix } -{ truncated_item_name } -{ suffix } "
206
198
207
199
if frappe .db .exists ("BOM" , name ):
208
- conflicting_bom = frappe .get_doc ("BOM" , name )
209
-
210
- if conflicting_bom .item != self .item :
211
- msg = _ ("A BOM with name {0} already exists for item {1}." ).format (
212
- frappe .bold (name ), frappe .bold (conflicting_bom .item )
213
- )
200
+ existing_boms = frappe .get_all (
201
+ "BOM" , filters = {"name" : ("like" , search_key ), "amended_from" : ["is" , "not set" ]}, pluck = "name"
202
+ )
214
203
215
- frappe .throw (
216
- _ ("{0}{1} Did you rename the item? Please contact Administrator / Tech support" ).format (
217
- msg , "<br>"
218
- )
219
- )
204
+ index = self .get_index_for_bom (existing_boms )
205
+ suffix = "%.3i" % index
206
+ name = f"{ prefix } -{ self .item } -{ suffix } "
220
207
221
208
self .name = name
222
209
210
+ def get_index_for_bom (self , existing_boms ):
211
+ index = 1
212
+ if existing_boms :
213
+ index = self .get_next_version_index (existing_boms )
214
+
215
+ return index
216
+
223
217
@staticmethod
224
218
def get_next_version_index (existing_boms : list [str ]) -> int :
225
219
# split by "/" and "-"
0 commit comments