diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 5c45e5d5b6..ca4a9bc125 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -395,7 +395,7 @@ class BOM(WebsiteGenerator): 'description' : d.description, 'image' : d.image, 'stock_uom' : d.stock_uom, - 'qty' : flt(d.stock_qty), + 'stock_qty' : flt(d.stock_qty), 'rate' : d.base_rate, })) @@ -404,16 +404,16 @@ class BOM(WebsiteGenerator): def add_to_cur_exploded_items(self, args): if self.cur_exploded_items.get(args.item_code): - self.cur_exploded_items[args.item_code]["qty"] += args.qty + self.cur_exploded_items[args.item_code]["stock_qty"] += args.stock_qty else: self.cur_exploded_items[args.item_code] = args - def get_child_exploded_items(self, bom_no, qty): + def get_child_exploded_items(self, bom_no, stock_qty): """ Add all items from Flat BOM of child BOM""" # Did not use qty_consumed_per_unit in the query, as it leads to rounding loss child_fb_items = frappe.db.sql("""select bom_item.item_code, bom_item.item_name, bom_item.description, - bom_item.stock_uom, bom_item.qty, bom_item.rate, - bom_item.qty / ifnull(bom.quantity, 1) as qty_consumed_per_unit + bom_item.stock_uom, bom_item.stock_qty, bom_item.rate, + bom_item.stock_qty / ifnull(bom.quantity, 1) as qty_consumed_per_unit from `tabBOM Explosion Item` bom_item, tabBOM bom where bom_item.parent = bom.name and bom.name = %s and bom.docstatus = 1""", bom_no, as_dict = 1) @@ -423,7 +423,7 @@ class BOM(WebsiteGenerator): 'item_name' : d['item_name'], 'description' : d['description'], 'stock_uom' : d['stock_uom'], - 'qty' : d['qty_consumed_per_unit']*qty, + 'stock_qty' : d['qty_consumed_per_unit']*stock_qty, 'rate' : flt(d['rate']), })) @@ -435,8 +435,8 @@ class BOM(WebsiteGenerator): ch = self.append('exploded_items', {}) for i in self.cur_exploded_items[d].keys(): ch.set(i, self.cur_exploded_items[d][i]) - ch.amount = flt(ch.qty) * flt(ch.rate) - ch.qty_consumed_per_unit = flt(ch.qty) / flt(self.quantity) + ch.amount = flt(ch.stock_qty) * flt(ch.rate) + ch.qty_consumed_per_unit = flt(ch.stock_qty) / flt(self.quantity) ch.docstatus = self.docstatus ch.db_insert() @@ -480,13 +480,13 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite from `tab{table}` bom_item, `tabBOM` bom, `tabItem` item where - bom_item.parent = bom.name - and bom_item.docstatus < 2 - and bom_item.parent = %(bom)s + bom_item.docstatus < 2 + and bom.name = %(bom)s + and bom_item.parent = bom.name and item.name = bom_item.item_code and is_stock_item = 1 {conditions} - group by item_code, stock_uom""" + group by item_code, stock_uom""" if fetch_exploded: query = query.format(table="BOM Explosion Item", diff --git a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json index f075840806..e1a3d4da53 100644 --- a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json +++ b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, "autoname": "hash", @@ -13,6 +14,7 @@ "engine": "InnoDB", "fields": [ { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -44,6 +46,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -72,6 +75,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -101,6 +105,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -129,6 +134,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -161,6 +167,7 @@ "width": "300px" }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -189,6 +196,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -218,6 +226,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -248,6 +257,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -276,11 +286,12 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "qty", + "fieldname": "stock_qty", "fieldtype": "Float", "hidden": 0, "ignore_user_permissions": 0, @@ -289,7 +300,7 @@ "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, - "label": "Qty", + "label": "Stock Qty", "length": 0, "no_copy": 0, "oldfieldname": "qty", @@ -306,6 +317,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -337,6 +349,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -365,6 +378,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -393,6 +407,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -424,6 +439,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -455,17 +471,17 @@ "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, "idx": 1, "image_view": 0, "in_create": 0, - "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-17 17:27:43.757983", + "modified": "2017-06-02 19:29:34.498719", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM Explosion Item", diff --git a/erpnext/manufacturing/doctype/bom_item/bom_item.json b/erpnext/manufacturing/doctype/bom_item/bom_item.json index 56af7a10d3..966b89bd4c 100644 --- a/erpnext/manufacturing/doctype/bom_item/bom_item.json +++ b/erpnext/manufacturing/doctype/bom_item/bom_item.json @@ -424,6 +424,8 @@ "label": "Stock Qty", "length": 0, "no_copy": 0, + "oldfieldname": "stock_qty", + "oldfieldtype": "Currency", "permlevel": 0, "precision": "", "print_hide": 0, diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 798e17486c..050c3c1c33 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -321,7 +321,7 @@ class ProductionPlanningTool(Document): # get all raw materials with sub assembly childs # Did not use qty_consumed_per_unit in the query, as it leads to rounding loss for d in frappe.db.sql("""select fb.item_code, - ifnull(sum(fb.qty/ifnull(bom.quantity, 1)), 0) as qty, + ifnull(sum(fb.stock_qty/ifnull(bom.quantity, 1)), 0) as qty, fb.description, fb.stock_uom, item.min_order_qty from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` item where bom.name = fb.parent and item.name = fb.item_code diff --git a/erpnext/patches/v8_0/update_stock_qty_value_in_bom_item.py b/erpnext/patches/v8_0/update_stock_qty_value_in_bom_item.py index bc69815fa2..9d227877ce 100644 --- a/erpnext/patches/v8_0/update_stock_qty_value_in_bom_item.py +++ b/erpnext/patches/v8_0/update_stock_qty_value_in_bom_item.py @@ -7,4 +7,5 @@ import frappe def execute(): frappe.reload_doc('manufacturing', 'doctype', 'bom_item') frappe.db.sql("update `tabBOM Item` set stock_qty = qty, uom = stock_uom") + frappe.db.sql("update `tabBOM Explosion Item` set stock_qty = qty") frappe.db.sql("update `tabBOM Scrap Item` set stock_qty = qty") \ No newline at end of file