[UPDT] ATTENDANCE: Auto check out for employees who forgot to checkout
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from attendance import scheduler
|
||||
|
||||
45
attendance/scheduler.py
Normal file
45
attendance/scheduler.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import datetime
|
||||
from datetime import datetime
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
|
||||
def auto_check_out():
|
||||
|
||||
from attendance.models import AttendanceActivity
|
||||
from base.models import EmployeeShiftSchedule
|
||||
from employee.models import Employee
|
||||
from attendance.views.clock_in_out import clock_out_attendance_and_activity
|
||||
|
||||
try:
|
||||
today = datetime.now()
|
||||
shift_schedules = EmployeeShiftSchedule.objects.all()
|
||||
employees = Employee.objects.all()
|
||||
for employee in employees:
|
||||
work_info = getattr(employee, "employee_work_info", None)
|
||||
shift_id = getattr(work_info, "shift_id", None)
|
||||
shift_schedule = shift_schedules.filter(
|
||||
day__day=today.strftime("%A").lower(), shift_id=shift_id
|
||||
).first()
|
||||
attendance_activity = AttendanceActivity.objects.filter(
|
||||
employee_id=employee, clock_out__isnull=True
|
||||
).first()
|
||||
if (
|
||||
shift_schedule
|
||||
and attendance_activity
|
||||
and attendance_activity.attendance_date < today.date()
|
||||
):
|
||||
if (
|
||||
not attendance_activity.clock_out
|
||||
and shift_schedule.start_time <= today.time()
|
||||
):
|
||||
clock_out_attendance_and_activity(
|
||||
employee=employee, date_today=today.date(), now=today.time().strftime("%H:%M"), out_datetime=today
|
||||
)
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
scheduler.add_job(auto_check_out, "interval", seconds=30)
|
||||
scheduler.start()
|
||||
Reference in New Issue
Block a user