diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index 365e52ba84..1203625958 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -84,12 +84,16 @@ def get_conditions(filters): def get_stock_ledger_entries(filters): conditions = get_conditions(filters) + + join_table_query = "" + if filters.get("item_group"): + join_table_query = "inner join `tabItem` item on item.name = sle.item_code" + return frappe.db.sql("""select sle.item_code, warehouse, sle.posting_date, sle.actual_qty, sle.valuation_rate, sle.company, sle.voucher_type, sle.qty_after_transaction, sle.stock_value_difference - from `tabStock Ledger Entry` sle force index (posting_sort_index) - inner join `tabItem` item on item.name = sle.item_code + from `tabStock Ledger Entry` sle force index (posting_sort_index) %s where sle.docstatus < 2 %s order by sle.posting_date, sle.posting_time, sle.name""" % - conditions, as_dict=1) + (join_table_query, conditions), as_dict=1) def get_item_warehouse_map(filters): iwb_map = {}