Skip to content

Commit

Permalink
fix: Sort lists before calling itertools.groupby
Browse files Browse the repository at this point in the history
(cherry picked from commit 45a6ecb)
  • Loading branch information
cogk authored and mergify[bot] committed Aug 9, 2024
1 parent f376abf commit d8939e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def get_data_query(self, based_on, data_based_on):
self.grouped_data = []

grouping_key = lambda o: (o["sales_stage"], o[based_on]) # noqa
for (sales_stage, _based_on), rows in groupby(self.query_result, grouping_key):
for (sales_stage, _based_on), rows in groupby(
sorted(self.query_result, key=grouping_key), key=grouping_key
):
self.grouped_data.append(
{
"sales_stage": sales_stage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def get_data(self):
self.grouped_data = []

grouping_key = lambda o: (o.get(self.pipeline_by) or "Not Assigned", o[self.period_by]) # noqa
for (pipeline_by, period_by), rows in groupby(self.query_result, grouping_key):
for (pipeline_by, period_by), rows in groupby(
sorted(self.query_result, key=grouping_key), grouping_key
):
self.grouped_data.append(
{
self.pipeline_by: pipeline_by,
Expand Down
2 changes: 1 addition & 1 deletion erpnext/selling/page/sales_funnel/sales_funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_opp_by_lead_source(from_date, to_date, company):
summary = {}
sales_stages = set()
group_key = lambda o: (o["source"], o["sales_stage"]) # noqa
for (source, sales_stage), rows in groupby(cp_opportunities, group_key):
for (source, sales_stage), rows in groupby(sorted(cp_opportunities, key=group_key), group_key):
summary.setdefault(source, {})[sales_stage] = sum(r["compound_amount"] for r in rows)
sales_stages.add(sales_stage)

Expand Down
3 changes: 2 additions & 1 deletion erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,8 @@ def create_delivery_note(source_name, target_doc=None):
)
)

for customer, rows in groupby(sales_orders, key=lambda so: so["customer"]):
group_key = lambda so: so["customer"] # noqa
for customer, rows in groupby(sorted(sales_orders, key=group_key), key=group_key):
sales_dict[customer] = {row.sales_order for row in rows}

if sales_dict:
Expand Down

0 comments on commit d8939e0

Please sign in to comment.