-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
Outdated
Show resolved
Hide resolved
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
Outdated
Show resolved
Hide resolved
@asmitahase can you review and give feed back |
if filter_by_shift: | ||
unmarked_attendance = _get_unmarked_attendance_with_shift(unmarked_attendance, shift, date) |
There was a problem hiding this comment.
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.
shift_assigned_employees = frappe.get_list( | ||
'Shift Assignment', | ||
filters = { | ||
'shift_type': shift, | ||
'start_date': ['<=', frappe.utils.getdate(date)], | ||
}, | ||
fields=['employee'] | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- 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. - 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?
hey @anwarpatelnoori could you fix the linter errors. |
Ok I will do this👍 |
WalkthroughAdds shift-based filtering to the Employee Attendance Tool. DocType: new "Filter by Shift" checkbox and "Shift" field now has mandatory_depends_on on that checkbox. Client JS now sends shift and filter_by_shift when loading employees. Server: get_employees gains shift and filter_by_shift parameters and uses a new helper _get_unmarked_attendance_with_shift to filter unmarked attendance by shift (assignments and default_shift). A unit test for the helper was added (duplicated test present). 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py (1)
157-157
: Remove whitespace from blank lines.Static analysis detected whitespace on blank lines that should be removed.
- +Also applies to: 183-183
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py (1)
94-101
: Consider adding end_date validation for shift assignments.The current query only checks
start_date <= date
but doesn't validate that the assignment hasn't expired. This could include employees with expired shift assignments.shift_assigned_employees = frappe.get_list( 'Shift Assignment', filters = { 'shift_type': shift, 'start_date': ['<=', frappe.utils.getdate(date)], + 'end_date': ['>=', frappe.utils.getdate(date)], }, fields=['employee'] )
Alternatively, you could use:
+ 'end_date': ['is', 'null'], # For open-ended assignments
Or use an OR condition to handle both cases.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.js
(1 hunks)hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
(3 hunks)hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
(3 hunks)hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
(2 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
157-157: Blank line contains whitespace
Remove whitespace from blank line
(W293)
183-183: Blank line contains whitespace
Remove whitespace from blank line
(W293)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
🔇 Additional comments (5)
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.js (1)
50-51
: LGTM! Clean integration of shift filtering parameters.The addition of
shift
andfilter_by_shift
parameters to the server call is correctly implemented and integrates well with the existingload_employees
function.hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.json (2)
106-106
: Good UX improvement with conditional mandatory logic.Making the shift field mandatory only when
filter_by_shift
is checked addresses the UX concern from previous reviews about confusing users who don't need shift filtering.
178-183
: Well-defined checkbox field for shift filtering.The
filter_by_shift
checkbox field is properly configured with appropriate defaults and labeling.hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py (2)
26-27
: LGTM! Clean function signature extension.The new parameters are properly typed and integrate well with the existing function signature.
92-120
: LGTM! Solid filtering logic implementation.The function correctly handles both shift assignments and default shifts, combines them efficiently using a set for deduplication, and filters the unmarked attendance appropriately.
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
Outdated
Show resolved
Hide resolved
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
Outdated
Show resolved
Hide resolved
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
Outdated
Show resolved
Hide resolved
286c026
to
b0798ab
Compare
@asmitahase, As there were lot of git conflicts , I have discarded all the commits and re opened PR and the updated the commit message according to semantic system . |
hey @anwarpatelnoori, |
@Mergifyio rebase |
✅ Branch has been successfully rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (3)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py (3)
158-164
: Fix the invalid end_time value.The shift type creation still has an invalid
end_time
value of"end_time"
which should be a proper time string format.- "end_time":"end_time", + "end_time": "17:00:00",
181-181
: Fix the default_shift assignment syntax.The
default_shift
field assignment is missing the proper reference to the shift name. It should referenceself.shift.name
instead of the shift object directly.- "default_shift": self.shift, + "default_shift": self.shift.name,
211-211
: Fix the shift name mismatch.The shift variable is set to "Morning Shift" but the actual shift created is named "Shift 1". This will cause the test to fail as the filtering function won't find any employees with the "Morning Shift" name.
- shift = "Morning Shift" + shift = self.shift.name
🧹 Nitpick comments (2)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py (2)
165-194
: Consider using more descriptive employee names.While the current implementation works, the employee names could be more descriptive to better reflect their role in the test scenario.
- "first_name": "Morning Shift Assigned", + "first_name": "Shift Assignment Employee", - "first_name": "Test Default Shift", + "first_name": "Default Shift Employee", - "first_name": "Test Not Assigned", + "first_name": "No Shift Employee",
196-203
: Improve shift assignment reference consistency.The shift assignment should use
self.shift.name
for consistency with other shift references in the codebase.- "shift_type": self.shift, + "shift_type": self.shift.name,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.js
(1 hunks)hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
(3 hunks)hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
(3 hunks)hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.js
- hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.json
- hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py (1)
hrms/hr/doctype/employee_attendance_tool/employee_attendance_tool.py (1)
_get_unmarked_attendance_with_shift
(92-120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
🔇 Additional comments (2)
hrms/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.py (2)
14-14
: LGTM! Import addition is correct.The import of
_get_unmarked_attendance_with_shift
is properly added to enable testing of the new shift-based filtering functionality.
214-220
: Test logic and assertions are well-structured.The test correctly validates that only employees with the specified shift (either through shift assignment or default shift) are returned by the filtering function. The assertions properly check for inclusion and exclusion of the expected employees.
Thanks for response @asmitahase . I have fixed the linter errors in local and pushed the changes |
|
@asmitahase updated |
Closes #3362
_get_unmarked_attendance_with_shift()
to fetch the employees based on shift assignmentAdded

Filter By Shift
check box in filters section and madeShift
reqdFilter.By.Shift.mp4
Summary by CodeRabbit
New Features
Bug Fixes
Tests
no-docs