From d95909c39a408b9839bacbb8236da83e7f380216 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 24 Jun 2019 12:57:44 +0530 Subject: [PATCH] fix: optimize bom update tool --- erpnext/manufacturing/doctype/bom/bom.py | 9 ++++++--- .../doctype/bom_update_tool/bom_update_tool.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 5c7375818fe..4a3c121d658 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -381,9 +381,12 @@ class BOM(WebsiteGenerator): frappe.throw(_("Same item has been entered multiple times. {0}").format(duplicate_list)) - def check_recursion(self): + def check_recursion(self, bom_list=[]): """ Check whether recursion occurs in any bom""" - bom_list = self.traverse_tree() + + if not bom_list: + bom_list = self.traverse_tree() + bom_nos = frappe.get_all('BOM Item', fields=["bom_no"], filters={'parent': ('in', bom_list), 'parenttype': 'BOM'}) @@ -405,7 +408,7 @@ class BOM(WebsiteGenerator): bom_list = self.traverse_tree(bom_list) for bom in bom_list: bom_obj = frappe.get_doc("BOM", bom) - bom_obj.check_recursion() + bom_obj.check_recursion(bom_list=bom_list) bom_obj.update_exploded_items() return bom_list diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py index a7d1d859dd7..87b8f67e53f 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py +++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py @@ -55,7 +55,7 @@ class BOMUpdateTool(Document): bom_list = [] data = frappe.db.sql(""" select distinct parent from `tabBOM Item` - where ifnull(bom_no, '') = %s and docstatus < 2 and parenttype='BOM'""", bom) + where bom_no = %s and docstatus < 2 and parenttype='BOM'""", bom) for d in data: bom_list.append(d[0])