Skip to content

feat: filter unmarked attendance by shift in employee attendance tool #3362 #3363

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

anwarpatelnoori
Copy link

@anwarpatelnoori anwarpatelnoori commented Jul 19, 2025

Closes #3362

Please provide enough information so that others can review your pull request:

  • Shift field is already present in Employee Attendance DocType.
  • Shift field is not used in filters while fetching employees
  • But while marking the attendance the field is used
  • So I added another _get_unmarked_attendance_with_shift() to fetch the employees based on shift assignment

Explain the details for making this change. What existing problem does the pull request solve?
If ERPNext setup has over 4,000 employees, and their HR team uses the Employee Attendance Tool exclusively to mark attendance.

  • Each shift contains around 1,000+ employees.
    
  • Currently, the tool fetches employees from all shifts, regardless of which shift is being assigned .
    
  • As a result, HR staff have to manually remove employees who are not part of the target shift before proceeding.
    
  • This process is time-consuming given the volume of employees.
    
  • A shift-based filter would significantly improve efficiency and accuracy when marking attendance.
    
image > Screenshots/GIFs

Moved the Shift field in filters section
image

HR.PR.mp4

@anwarpatelnoori
Copy link
Author

@asmitahase can you review and give feed back

Comment on lines +73 to +74
if filter_by_shift:
unmarked_attendance = _get_unmarked_attendance_with_shift(unmarked_attendance, shift, date)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Implementing filter by shift this way has one consequence of fetching employees with empty default shift if filter_by_shift is checked but shift isn't set. For other filters like company, department etc, if there's no value for filters all employees are fetched.

Comment on lines +94 to +101
shift_assigned_employees = frappe.get_list(
'Shift Assignment',
filters = {
'shift_type': shift,
'start_date': ['<=', frappe.utils.getdate(date)],
},
fields=['employee']
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

One more caveat is, because we're getting data from two different doctypes, get_list isn't enough to ensure all the filters are "and"ed e.g if someone wants to fetch employees from department A and shift B, it won't be ensured because shift assignment may have employees belonging to different department.

It's better to use query builder to select employees in this case. And while we're half way there, might as well use that to separate unmarked and half day marked employees too. I'll contribute to this. Looks good enough for now.

Copy link
Author

@anwarpatelnoori anwarpatelnoori Jul 30, 2025

Choose a reason for hiding this comment

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

Thanks for your feedback! @asmitahase . The cases you mentioned are already covered in the current filter logic.

  1. The employee_list is first filtered to get the unmarked attendance through the _get_unmarked_attendance function, which ensures that all necessary conditions (such as department, grades or other filters) are applied.
  2. Using the same filtered unmarked_attendance, I'm further refining it by checking the shift assignments (both default shifts and shift assignments). This ensures that only employees assigned to the relevant shift are included.

Please correct me if I’m wrong in the current logic. Should I work on the requested changes if the filtering with shift logic is incorrect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Employee Attendance Tool Doctype needs shift wise filter for fetching unmarked Employees
2 participants