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

fix: Sort lists before calling itertools.groupby (backport #1997) #2009

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For license information, please see license.txt


import itertools
from datetime import datetime, timedelta
from itertools import groupby

import frappe
from frappe.model.document import Document
Expand Down Expand Up @@ -36,7 +36,8 @@ def process_auto_attendance(self):

logs = self.get_employee_checkins()

for key, group in itertools.groupby(logs, key=lambda x: (x["employee"], x["shift_start"])):
group_key = lambda x: (x["employee"], x["shift_start"]) # noqa
for key, group in groupby(sorted(logs, key=group_key), key=group_key):
single_shift_logs = list(group)
attendance_date = key[1].date()
employee = key[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def get_employee_related_details(filters: Filters) -> tuple[dict, list]:
emp_map = {}

if group_by:
for parameter, employees in groupby(employee_details, key=lambda d: d[group_by]):
group_key = lambda d: d[group_by] # noqa
for parameter, employees in groupby(sorted(employee_details, key=group_key), key=group_key):
group_by_param_values.append(parameter)
emp_map.setdefault(parameter, frappe._dict())

Expand Down
Loading