[fix] Run Stock Balance report only after one of the filters is set
This commit is contained in:
parent
aac4dcedc8
commit
0902fb2e3d
@ -22,7 +22,40 @@ frappe.query_reports["Stock Balance"] = {
|
|||||||
"label": __("Item"),
|
"label": __("Item"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"width": "80",
|
"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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ from frappe.utils import flt, getdate
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns()
|
||||||
item_map = get_item_details(filters)
|
item_map = get_item_details(filters)
|
||||||
iwb_map = get_item_warehouse_map(filters)
|
iwb_map = get_item_warehouse_map(filters)
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ def execute(filters=None):
|
|||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns():
|
||||||
"""return columns based on filters"""
|
"""return columns"""
|
||||||
|
|
||||||
columns = [
|
columns = [
|
||||||
_("Item")+":Link/Item:100",
|
_("Item")+":Link/Item:100",
|
||||||
@ -68,9 +68,11 @@ def get_conditions(filters):
|
|||||||
if filters.get("item_code"):
|
if filters.get("item_code"):
|
||||||
conditions += " and item_code = '%s'" % frappe.db.escape(filters.get("item_code"), percent=False)
|
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
|
return conditions
|
||||||
|
|
||||||
#get all details
|
|
||||||
def get_stock_ledger_entries(filters):
|
def get_stock_ledger_entries(filters):
|
||||||
conditions = get_conditions(filters)
|
conditions = get_conditions(filters)
|
||||||
return frappe.db.sql("""select item_code, warehouse, posting_date, actual_qty, valuation_rate,
|
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
|
return iwb_map
|
||||||
|
|
||||||
def get_item_details(filters):
|
def get_item_details(filters):
|
||||||
item_map = {}
|
condition = ''
|
||||||
for d in frappe.db.sql("select name, item_name, stock_uom, item_group, brand, \
|
value = ()
|
||||||
description from tabItem", as_dict=1):
|
if filters.get("item_code"):
|
||||||
item_map.setdefault(d.name, d)
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user