[fix] Run Stock Balance report only after one of the filters is set

This commit is contained in:
Anand Doshi 2016-03-07 13:11:59 +05:30
parent aac4dcedc8
commit 0902fb2e3d
2 changed files with 50 additions and 11 deletions

View File

@ -22,7 +22,40 @@ frappe.query_reports["Stock Balance"] = {
"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);
}
}

View File

@ -9,7 +9,7 @@ from frappe.utils import flt, getdate
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 @@ def execute(filters=None):
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 @@ def get_conditions(filters):
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 @@ def get_item_warehouse_map(filters):
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)