Skip to content

Commit

Permalink
fix: item group filter in sales person wise report
Browse files Browse the repository at this point in the history
(cherry picked from commit f4d418e)
  • Loading branch information
ruthra-kumar authored and mergify[bot] committed Dec 3, 2023
1 parent 6db63c9 commit eee9062
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


import frappe
from frappe import _, msgprint
from frappe import _, msgprint, qb
from frappe.query_builder import Criterion

from erpnext import get_company_currency

Expand Down Expand Up @@ -214,24 +215,33 @@ def get_conditions(filters, date_field):
if items:
conditions.append("dt_item.item_code in (%s)" % ", ".join(["%s"] * len(items)))
values += items
else:
# return empty result, if no items are fetched after filtering on 'item group' and 'brand'
conditions.append("dt_item.item_code = Null")

return " and ".join(conditions), values


def get_items(filters):
if filters.get("item_group"):
key = "item_group"
elif filters.get("brand"):
key = "brand"
else:
key = ""
item = qb.DocType("Item")

items = []
if key:
items = frappe.db.sql_list(
"""select name from tabItem where %s = %s""" % (key, "%s"), (filters[key])
item_query_conditions = []
if filters.get("item_group"):
# Handle 'Parent' nodes as well.
item_group = qb.DocType("Item Group")
lft, rgt = frappe.db.get_all(
"Item Group", filters={"name": filters.get("item_group")}, fields=["lft", "rgt"], as_list=True
)[0]
item_group_query = (
qb.from_(item_group)
.select(item_group.name)
.where((item_group.lft >= lft) & (item_group.rgt <= rgt))
)
item_query_conditions.append(item.item_group.isin(item_group_query))
if filters.get("brand"):
item_query_conditions.append(item.brand == filters.get("brand"))

items = qb.from_(item).select(item.name).where(Criterion.all(item_query_conditions)).run()
return items


Expand Down

0 comments on commit eee9062

Please sign in to comment.