From 149b4e59851efcf28fb1fddfe42fb396a2329b98 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 27 Jan 2020 15:20:30 +0530 Subject: [PATCH] chore: warn bom naming conflict (#20244) Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> --- erpnext/manufacturing/doctype/bom/bom.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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('_', '-')