Fetch BOM items in Production Order in the same order as BOM
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index e86f1bb..b308e09 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -512,7 +512,6 @@
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
query = """select
- (Select idx from `tabBOM Item` where item_code = bom_item.item_code and parent = %(parent)s ) as idx,
bom_item.item_code,
item.item_name,
sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(qty)s as qty,
@@ -538,15 +537,15 @@
if fetch_exploded:
query = query.format(table="BOM Explosion Item",
where_conditions="""and item.is_sub_contracted_item = 0""",
- select_columns = ", bom_item.source_warehouse")
+ select_columns = ", bom_item.source_warehouse, (Select idx from `tabBOM Item` where item_code = bom_item.item_code and parent = %(parent)s ) as idx")
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
elif fetch_scrap_items:
- query = query.format(table="BOM Scrap Item", where_conditions="", select_columns="")
- items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
+ query = query.format(table="BOM Scrap Item", where_conditions="", select_columns=", bom_item.idx")
+ items = frappe.db.sql(query, { "qty": qty, "bom": bom }, as_dict=True)
else:
query = query.format(table="BOM Item", where_conditions="",
- select_columns = ", bom_item.source_warehouse")
- items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
+ select_columns = ", bom_item.source_warehouse, bom_item.idx")
+ items = frappe.db.sql(query, { "qty": qty, "bom": bom }, as_dict=True)
for item in items:
if item_dict.has_key(item.item_code):