Skip to content

Commit

Permalink
fix: Sort lists before calling itertools.groupby (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
cogk authored Jul 27, 2024
1 parent 9366877 commit 0265ca9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit 0265ca9

Please sign in to comment.