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

feat: Scheduling Multiple shifts and Auto Attendance #30588

Merged
merged 36 commits into from
Apr 7, 2022

Conversation

ruchamahabal
Copy link
Member

@ruchamahabal ruchamahabal commented Apr 6, 2022

Problem

  • Earlier, only 1 Shift Type could be assigned to an employee for one day.
  • However, in some organizations, employees could be working in multiple shifts (Morning Shift, Evening Shift) on the same day.

What Changes?

Schedule multiple shifts

  • Users can make multiple non-overlapping Shift Assignments for the same employee on the same day

Shift Request

  • Users can make multiple non-overlapping Shift Requests for the same employee on the same day

Fetching shift in Employee Check In

  • When employee check-ins are logged via biometric or manually, the exact shift based on the timestamp is fetched. Before, shifts used to be fetched based on date. Now they are timestamp specific.
  • Handles shifts spanning over 2 different days (eg: 23:00 - 2:00), midnight shifts.
  • Shift fetching used to fail on timing boundaries, this is fixed.
  • Handles 2 consecutive shifts if they are overlapping within grace periods.

Attendance

  • Earlier, only 1 attendance record could be marked for 1 day.
  • Now multiple attendance records can be marked for each shift. Eg: employee can be absent for one shift, present for another on the same day
  • Auto Attendance now, takes care of marking shift specific attendance and not for the whole day
  • Earlier, employees with no attendance records on a specific date used to be marked absent via Auto Attendance. Now, this also checks for shift-wise attendance records along with the date. So, only if attendance is not marked for a particular shift/for the whole day, the employee will be marked absent.

Attendance Reports

  • Added shift-wise attendance against employees
  • Added legend for status abbr with full form and color.
  • Formatter for data to quickly identify cells with lesser cognitive load.
  • Refactored Monthly Attendance Sheet code. Can still be better but will leave it for the next iteration.

Before:
image

After:
image

Impact on Payroll

If there are multiple attendance records marked for a single day with separate shifts, each record will be considered as 1 Payment Day in payroll. So if an employee works 2 shifts in a single day this contributes to 2 payment days in Payroll. No code level changes are done for this

Documentation: Added docs for Monthly Attendance Sheet only since others are mostly backend changes: https://docs.erpnext.com/docs/v14/user/manual/en/human-resources/human-resources-reports#3-monthly-attendance-sheet
Also closes #29210

ToDo

  • Allow scheduling multiple shifts
  • Shift fetching in employee check-ins
  • Multiple attendance records for the same day
  • Auto Attendance for multiple shifts
  • Handle impact on attendance reports
  • Refactor Shift Request Overlapping validation
  • Test cases
  • Documentation

- convert raw query to frappe.qb

- check for overlapping timings if dates overlap

- translation friendly error messages with link to overlapping doc
- break down into smaller functions

- make it work with multiple shifts

- this will mark employee as absent per shift, meaning employee can be present for one shift and absent for another on the same day
- split into smaller functions

- add type hints

- get rid of unnecessary db calls and loops

- add docstrings for functions
- legend with colors and full form for status abbreviations
- check half day attendance threshold before absent threshold to avoid half day getting marked as absent

- round working hours to 2 digits for better accuracy

- start and end dates for absent attendance marking
- commonify time overlap function between request and assignment

- add tests for shift request overlap
- skip auto attendance in case of overlapping shift attendance record

- this case won't occur in case of shift assignment, since it will not allow overlapping shifts to be assigned

- can happen if manual attendance records are created
@codecov
Copy link

codecov bot commented Apr 7, 2022

Codecov Report

Merging #30588 (7ba66b0) into develop (f1fd4e5) will increase coverage by 0.30%.
The diff coverage is 94.35%.

@@             Coverage Diff             @@
##           develop   #30588      +/-   ##
===========================================
+ Coverage    60.92%   61.22%   +0.30%     
===========================================
  Files         1083     1083              
  Lines        69224    69356     +132     
===========================================
+ Hits         42173    42466     +293     
+ Misses       27051    26890     -161     
Impacted Files Coverage Δ
erpnext/hr/doctype/shift_type/shift_type.py 86.07% <87.09%> (+64.55%) ⬆️
...xt/hr/doctype/shift_assignment/shift_assignment.py 75.72% <89.14%> (+26.34%) ⬆️
...nthly_attendance_sheet/monthly_attendance_sheet.py 95.60% <96.26%> (+33.21%) ⬆️
erpnext/hr/doctype/attendance/attendance.py 71.52% <100.00%> (+9.13%) ⬆️
...xt/hr/doctype/employee_checkin/employee_checkin.py 93.63% <100.00%> (+8.58%) ⬆️
erpnext/hr/doctype/shift_request/shift_request.py 93.24% <100.00%> (+7.52%) ⬆️
erpnext/accounts/doctype/bank/bank.py 71.42% <0.00%> (-14.29%) ⬇️
...em_wise_sales_register/item_wise_sales_register.py 51.58% <0.00%> (-11.32%) ⬇️
...urity_shortfall/process_loan_security_shortfall.py 93.75% <0.00%> (-6.25%) ⬇️
...pnext/accounts/report/gross_profit/gross_profit.py 81.48% <0.00%> (-5.77%) ⬇️
... and 37 more

@ruchamahabal ruchamahabal merged commit 0562eb5 into frappe:develop Apr 7, 2022
@ruchamahabal ruchamahabal deleted the multiple-shifts branch April 7, 2022 13:14
@mohsinalimat
Copy link
Contributor

Could you please support v13 as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Error on creating a non - overlapping shift assignment for same day for same employee
2 participants