[Fix] BOM Update Tool not update grandparent's exploded BOM (#13026)

This commit is contained in:
rohitwaghchaure 2018-02-22 11:32:09 +05:30 committed by Nabin Hait
parent 0bde9e11c7
commit 23a2b65576
2 changed files with 24 additions and 5 deletions

View File

@ -200,6 +200,14 @@ class BOM(WebsiteGenerator):
if not from_child_bom:
frappe.msgprint(_("Cost Updated"))
def update_parent_cost(self):
if self.total_cost:
cost = self.total_cost / self.quantity
frappe.db.sql("""update `tabBOM Item` set rate=%s, amount=stock_qty*%s
where bom_no = %s and docstatus < 2 and parenttype='BOM'""",
(cost, cost, self.name))
def get_bom_unitcost(self, bom_no):
bom = frappe.db.sql("""select name, base_total_cost/quantity as unit_cost from `tabBOM`
where is_active = 1 and name = %s""", bom_no, as_dict=1)

View File

@ -13,11 +13,14 @@ class BOMUpdateTool(Document):
def replace_bom(self):
self.validate_bom()
self.update_new_bom()
bom_list = self.get_parent_boms()
bom_list = self.get_parent_boms(self.new_bom)
updated_bom = []
for bom in bom_list:
bom_obj = frappe.get_doc("BOM", bom)
updated_bom = bom_obj.update_cost_and_exploded_items(updated_bom)
bom_obj.calculate_cost()
bom_obj.update_parent_cost()
bom_obj.db_update()
frappe.msgprint(_("BOM replaced"))
@ -38,10 +41,18 @@ class BOMUpdateTool(Document):
rate=%s, amount=stock_qty*%s where bom_no = %s and docstatus < 2 and parenttype='BOM'""",
(self.new_bom, new_bom_unitcost, new_bom_unitcost, self.current_bom))
def get_parent_boms(self):
return [d[0] for d in frappe.db.sql("""select distinct parent
from `tabBOM Item` where ifnull(bom_no, '') = %s and docstatus < 2 and parenttype='BOM'""",
self.new_bom)]
def get_parent_boms(self, bom, bom_list=None):
if not bom_list:
bom_list = []
data = frappe.db.sql(""" select distinct parent from `tabBOM Item`
where ifnull(bom_no, '') = %s and docstatus < 2 and parenttype='BOM'""", bom)
for d in data:
bom_list.append(d[0])
self.get_parent_boms(d[0], bom_list)
return bom_list
@frappe.whitelist()
def enqueue_update_cost():