fix(manufacturing): handle duplicate root BOM items (#58614)

* fix(manufacturing): handle duplicate root BOM items

* test(manufacturing): remove duplicate root item test

(cherry picked from commit 24209ae699)

# Conflicts:
#	erpnext/manufacturing/doctype/bom_creator/bom_creator.py
This commit is contained in:
Mihir Kandoi
2026-08-31 19:34:26 +05:30
committed by Mergify
parent 4cff4b7cec
commit bd1d79373a

View File

@@ -76,6 +76,37 @@ class BOMCreator(Document):
def validate(self):
self.validate_items()
<<<<<<< HEAD
=======
self.validate_duplicate_item()
def validate_duplicate_item(self):
# If same items added multiple times under same parent, raise error
item_map = {}
for row in self.items:
if not row.fg_reference_id:
continue
key = (row.item_code, row.fg_reference_id)
if key in item_map:
frappe.throw(
_(
"Item {0} added multiple times under the same parent item {1} at rows {2} and {3}"
).format(bold(row.item_code), bold(row.fg_item), item_map[key], row.idx),
title=_("Duplicate Item Under Same Parent"),
)
else:
item_map[key] = row.idx
def validate_finished_good(self):
is_stock_item = frappe.get_cached_value("Item", self.item_code, "is_stock_item")
if is_stock_item and self.is_phantom:
frappe.throw(_("Phantom BOM cannot be created for stock item {0}.").format(self.item_code))
elif not is_stock_item and not self.is_phantom:
frappe.throw(
_("Non-phantom BOM cannot be created for non-stock item {0}.").format(self.item_code)
)
>>>>>>> 24209ae (fix(manufacturing): handle duplicate root BOM items (#58614))
def validate_items(self):
for row in self.items: