From d871e21a40943b3e9d52e2dd7233a128fa0f0ff6 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sat, 7 Dec 2024 12:20:58 +0530 Subject: [PATCH] fix: BOM name issue (#44586) --- erpnext/manufacturing/doctype/bom/bom.js | 14 +++++----- erpnext/manufacturing/doctype/bom/bom.py | 34 ++++++++++-------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index cfed0c7ad09..926293a6cc3 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -301,15 +301,15 @@ frappe.ui.form.on("BOM", { }; }, }); - - fields.push({ - fieldtype: "Check", - label: __("Use Multi-Level BOM"), - fieldname: "use_multi_level_bom", - default: 1, - }); } + fields.push({ + fieldtype: "Check", + label: __("Use Multi-Level BOM"), + fieldname: "use_multi_level_bom", + default: 1, + }); + if (!skip_qty_field) { fields.push({ fieldtype: "Float", diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 0adadda659c..14f9f3a8f7c 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -182,15 +182,7 @@ class BOM(WebsiteGenerator): "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: - index = 1 + index = self.get_index_for_bom(existing_boms) prefix = self.doctype suffix = "%.3i" % index # convert index to string (1 -> "001") @@ -208,21 +200,23 @@ class BOM(WebsiteGenerator): name = f"{prefix}-{truncated_item_name}-{suffix}" if frappe.db.exists("BOM", name): - conflicting_bom = frappe.get_doc("BOM", name) + existing_boms = frappe.get_all( + "BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name" + ) - if conflicting_bom.item != self.item: - msg = _("A BOM with name {0} already exists for item {1}.").format( - frappe.bold(name), frappe.bold(conflicting_bom.item) - ) - - frappe.throw( - _("{0}{1} Did you rename the item? Please contact Administrator / Tech support").format( - msg, "
" - ) - ) + index = self.get_index_for_bom(existing_boms) + suffix = "%.3i" % index + name = f"{prefix}-{self.item}-{suffix}" self.name = name + def get_index_for_bom(self, existing_boms): + index = 1 + if existing_boms: + index = self.get_next_version_index(existing_boms) + + return index + @staticmethod def get_next_version_index(existing_boms: list[str]) -> int: # split by "/" and "-"