[fix] Run Stock Balance report only after one of the filters is set
diff --git a/erpnext/stock/report/stock_balance/stock_balance.js b/erpnext/stock/report/stock_balance/stock_balance.js
index db334f8..1af32ed 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.js
+++ b/erpnext/stock/report/stock_balance/stock_balance.js
@@ -22,7 +22,40 @@
"label": __("Item"),
"fieldtype": "Link",
"width": "80",
- "options": "Item"
+ "options": "Item",
+ "reqd": 1,
+ "on_change": function(me) {
+ frappe.query_reports["Stock Balance"].toggle_mandatory_filters(me);
+ }
+ },
+ {
+ "fieldname": "warehouse",
+ "label": __("Warehouse"),
+ "fieldtype": "Link",
+ "width": "80",
+ "options": "Warehouse",
+ "reqd": 1,
+ "on_change": function(me) {
+ frappe.query_reports["Stock Balance"].toggle_mandatory_filters(me);
+ }
+ },
+ ],
+
+ "toggle_mandatory_filters": function(me) {
+ var values = me.get_values(false);
+ var item_filter = me.filters_by_name["item_code"];
+ var warehouse_filter = me.filters_by_name["warehouse"];
+
+ if (values.item_code) {
+ warehouse_filter.df.reqd = 0;
+ } else if (values.warehouse) {
+ item_filter.df.reqd = 0;
+ } else {
+ item_filter.df.reqd = 1;
+ warehouse_filter.df.reqd = 1;
}
- ]
+
+ item_filter.set_mandatory(values.item_code);
+ warehouse_filter.set_mandatory(values.warehouse);
+ }
}
diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py
index 7dd728f..d465050 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.py
+++ b/erpnext/stock/report/stock_balance/stock_balance.py
@@ -9,7 +9,7 @@
def execute(filters=None):
if not filters: filters = {}
- columns = get_columns(filters)
+ columns = get_columns()
item_map = get_item_details(filters)
iwb_map = get_item_warehouse_map(filters)
@@ -30,8 +30,8 @@
return columns, data
-def get_columns(filters):
- """return columns based on filters"""
+def get_columns():
+ """return columns"""
columns = [
_("Item")+":Link/Item:100",
@@ -68,9 +68,11 @@
if filters.get("item_code"):
conditions += " and item_code = '%s'" % frappe.db.escape(filters.get("item_code"), percent=False)
+ if filters.get("warehouse"):
+ conditions += " and warehouse = '%s'" % frappe.db.escape(filters.get("warehouse"), percent=False)
+
return conditions
-#get all details
def get_stock_ledger_entries(filters):
conditions = get_conditions(filters)
return frappe.db.sql("""select item_code, warehouse, posting_date, actual_qty, valuation_rate,
@@ -125,9 +127,13 @@
return iwb_map
def get_item_details(filters):
- item_map = {}
- for d in frappe.db.sql("select name, item_name, stock_uom, item_group, brand, \
- description from tabItem", as_dict=1):
- item_map.setdefault(d.name, d)
+ condition = ''
+ value = ()
+ if filters.get("item_code"):
+ condition = "where item_code=%s"
+ value = (filters["item_code"],)
- return item_map
+ items = frappe.db.sql("""select name, item_name, stock_uom, item_group, brand, description
+ from tabItem {condition}""".format(condition=condition), value, as_dict=1)
+
+ return dict((d.name, d) for d in items)