From 6d0842465b28fa2ff029cfda65af58c27cb6e71b Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Fri, 30 Sep 2022 15:18:10 +0530 Subject: [PATCH] fix: don't allow to update `Maintain Stock` if the item has a `BOM` --- erpnext/stock/doctype/item/item.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 143fe408c3..c8bb1b960e 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -937,17 +937,21 @@ class Item(Document): "Purchase Order Item", "Material Request Item", "Product Bundle", + "BOM", ] for doctype in linked_doctypes: filters = {"item_code": self.name, "docstatus": 1} - if doctype == "Product Bundle": - filters = {"new_item_code": self.name} + if doctype in ("Product Bundle", "BOM"): + if doctype == "Product Bundle": + filters = {"new_item_code": self.name} + fieldname = "new_item_code as docname" + else: + filters = {"item": self.name, "docstatus": 1} + fieldname = "name as docname" - if linked_doc := frappe.db.get_value( - doctype, filters, ["new_item_code as docname"], as_dict=True - ): + if linked_doc := frappe.db.get_value(doctype, filters, fieldname, as_dict=True): return linked_doc.update({"doctype": doctype}) elif doctype in (