new item group filter in the stock ledger report (#10400)

This commit is contained in:
Manas Solanki 2017-08-16 11:35:04 +05:30 committed by Makarand Bauskar
parent 44b088c6b3
commit 0371d5a326
2 changed files with 21 additions and 4 deletions

View File

@ -37,6 +37,12 @@ frappe.query_reports["Stock Ledger"] = {
"fieldtype": "Link", "fieldtype": "Link",
"options": "Item" "options": "Item"
}, },
{
"fieldname":"item_group",
"label": __("Item Group"),
"fieldtype": "Link",
"options": "Item Group"
},
{ {
"fieldname":"batch_no", "fieldname":"batch_no",
"label": __("Batch No"), "label": __("Batch No"),

View File

@ -65,7 +65,7 @@ def get_stock_ledger_entries(filters):
def get_item_details(filters): def get_item_details(filters):
item_details = {} item_details = {}
for item in frappe.db.sql("""select name, item_name, description, item_group, for item in frappe.db.sql("""select name, item_name, description, item_group,
brand, stock_uom from `tabItem` {item_conditions}"""\ brand, stock_uom from `tabItem` item {item_conditions}"""\
.format(item_conditions=get_item_conditions(filters)), filters, as_dict=1): .format(item_conditions=get_item_conditions(filters)), filters, as_dict=1):
item_details.setdefault(item.name, item) item_details.setdefault(item.name, item)
@ -74,9 +74,11 @@ def get_item_details(filters):
def get_item_conditions(filters): def get_item_conditions(filters):
conditions = [] conditions = []
if filters.get("item_code"): if filters.get("item_code"):
conditions.append("name=%(item_code)s") conditions.append("item.name=%(item_code)s")
if filters.get("brand"): if filters.get("brand"):
conditions.append("brand=%(brand)s") conditions.append("item.brand=%(brand)s")
if filters.get("item_group"):
conditions.append(get_item_group_condition(filters.get("item_group")))
return "where {}".format(" and ".join(conditions)) if conditions else "" return "where {}".format(" and ".join(conditions)) if conditions else ""
@ -84,7 +86,7 @@ def get_sle_conditions(filters):
conditions = [] conditions = []
item_conditions=get_item_conditions(filters) item_conditions=get_item_conditions(filters)
if item_conditions: if item_conditions:
conditions.append("""item_code in (select name from tabItem conditions.append("""sle.item_code in (select item.name from tabItem item
{item_conditions})""".format(item_conditions=item_conditions)) {item_conditions})""".format(item_conditions=item_conditions))
if filters.get("warehouse"): if filters.get("warehouse"):
conditions.append(get_warehouse_condition(filters.get("warehouse"))) conditions.append(get_warehouse_condition(filters.get("warehouse")))
@ -122,3 +124,12 @@ def get_warehouse_condition(warehouse):
warehouse_details.rgt) warehouse_details.rgt)
return '' return ''
def get_item_group_condition(item_group):
item_group_details = frappe.db.get_value("Item Group", item_group, ["lft", "rgt"], as_dict=1)
if item_group_details:
return "item.item_group in (select ig.name from `tabItem Group` ig \
where ig.lft >= %s and ig.rgt <= %s and item.item_group = ig.name)"%(item_group_details.lft,
item_group_details.rgt)
return ''