diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 04f6fc66c7..7f8bd67a52 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -47,7 +47,18 @@ class BOM(WebsiteGenerator): else: idx = 1 - self.name = 'BOM-' + self.item + ('-%.3i' % idx) + name = 'BOM-' + self.item + ('-%.3i' % idx) + if frappe.db.exists("BOM", name): + conflicting_bom = frappe.get_doc("BOM", name) + + if conflicting_bom.item != self.item: + + frappe.throw(_("""A BOM with name {0} already exists for item {1}. +
Did you rename the item? Please contact Administrator / Tech support + """).format(frappe.bold(name), frappe.bold(conflicting_bom.item))) + + self.name = name + def validate(self): self.route = frappe.scrub(self.name).replace('_', '-')