Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item group filter shown parent and its child group items #37254

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,18 @@ def get_conditions(filters):
("from_date", " and `tabPurchase Invoice`.posting_date>=%(from_date)s"),
("to_date", " and `tabPurchase Invoice`.posting_date<=%(to_date)s"),
("mode_of_payment", " and ifnull(mode_of_payment, '') = %(mode_of_payment)s"),
("item_group", " and ifnull(`tabPurchase Invoice Item`.item_group, '') = %(item_group)s"),
):
if filters.get(opts[0]):
conditions += opts[1]
if filters.get("item_group"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nandhinidevi123 A better way to do this would be https://github.com/frappe/erpnext/blob/develop/erpnext/accounts/report/financial_statements.py#L591

Also, the code is not formatted, please setup linters locally by referring https://github.com/frappe/erpnext/wiki/Pull-Request-Checklist#linting and then reopen the PR

parent_grps = [filters.get("item_group")]
child_groups = []
for i in parent_grps:
child_groups.extend(frappe.get_all('Item Group', filters={'parent_item_group':['in', i]}, pluck='name')+frappe.get_all('Item Group', filters={'name':['in', i], "is_group":0}, pluck='name'))
parent_grps.extend(frappe.get_all('Item Group', filters={'parent_item_group':['in', i], 'is_group':1}, pluck='name'))

child_groups+=parent_grps
conditions += f"""and ifnull(`tabPurchase Invoice Item`.item_group, '') in ("{'","'.join(child_groups)}")"""

if not filters.get("group_by"):
conditions += (
Expand Down