[Fix] Timeout issue while saving multilevel BOM (#13118)

This commit is contained in:
rohitwaghchaure 2018-03-01 13:15:25 +05:30 committed by Nabin Hait
parent c10bbd6aa7
commit a942722619

View File

@ -47,7 +47,6 @@ class BOM(WebsiteGenerator):
self.validate_currency() self.validate_currency()
self.set_conversion_rate() self.set_conversion_rate()
self.validate_uom_is_interger() self.validate_uom_is_interger()
self.update_stock_qty()
self.set_bom_material_details() self.set_bom_material_details()
self.validate_materials() self.validate_materials()
self.validate_operations() self.validate_operations()
@ -247,14 +246,12 @@ class BOM(WebsiteGenerator):
set_default(self, "item") set_default(self, "item")
item = frappe.get_doc("Item", self.item) item = frappe.get_doc("Item", self.item)
if item.default_bom != self.name: if item.default_bom != self.name:
item.default_bom = self.name frappe.db.set_value('Item', self.item, 'default_bom', self.name)
item.save(ignore_permissions = True)
else: else:
frappe.db.set(self, "is_default", 0) frappe.db.set(self, "is_default", 0)
item = frappe.get_doc("Item", self.item) item = frappe.get_doc("Item", self.item)
if item.default_bom == self.name: if item.default_bom == self.name:
item.default_bom = None frappe.db.set_value('Item', self.item, 'default_bom', None)
item.save(ignore_permissions = True)
def clear_operations(self): def clear_operations(self):
if not self.with_operations: if not self.with_operations:
@ -291,6 +288,8 @@ class BOM(WebsiteGenerator):
m.uom = m.stock_uom m.uom = m.stock_uom
m.qty = m.stock_qty m.qty = m.stock_qty
m.db_update()
def validate_uom_is_interger(self): def validate_uom_is_interger(self):
from erpnext.utilities.transaction_base import validate_uom_is_integer from erpnext.utilities.transaction_base import validate_uom_is_integer
validate_uom_is_integer(self, "uom", "qty", "BOM Item") validate_uom_is_integer(self, "uom", "qty", "BOM Item")
@ -333,19 +332,23 @@ class BOM(WebsiteGenerator):
def check_recursion(self): def check_recursion(self):
""" Check whether recursion occurs in any bom""" """ Check whether recursion occurs in any bom"""
bom_list = self.traverse_tree()
bom_nos = frappe.get_all('BOM Item', fields=["bom_no"],
filters={'parent': ('in', bom_list), 'parenttype': 'BOM'})
check_list = [['parent', 'bom_no', 'parent'], ['bom_no', 'parent', 'child']] raise_exception = False
for d in check_list: if bom_nos and self.name in [d.bom_no for d in bom_nos]:
bom_list, count = [self.name], 0 raise_exception = True
while (len(bom_list) > count ):
boms = frappe.db.sql(" select %s from `tabBOM Item` where %s = %s and parenttype='BOM'" % if not raise_exception:
(d[0], d[1], '%s'), cstr(bom_list[count])) bom_nos = frappe.get_all('BOM Item', fields=["parent"],
count = count + 1 filters={'bom_no': self.name, 'parenttype': 'BOM'})
for b in boms:
if b[0] == self.name: if self.name in [d.parent for d in bom_nos]:
frappe.throw(_("BOM recursion: {0} cannot be parent or child of {2}").format(b[0], self.name)) raise_exception = True
if b[0]:
bom_list.append(b[0]) if raise_exception:
frappe.throw(_("BOM recursion: {0} cannot be parent or child of {2}").format(self.name, self.name))
def update_cost_and_exploded_items(self, bom_list=[]): def update_cost_and_exploded_items(self, bom_list=[]):
bom_list = self.traverse_tree(bom_list) bom_list = self.traverse_tree(bom_list)