If an employee is coming to office at 8:00 pm and going at 4:00 am. How to deal with it?
Right now i am using this to move attendance as we are using a zktecho device.
if atten:
for emp in atten:
if emp:
employee_dic = atten[emp]
sorted_employee_dic = sorted(employee_dic.items(), key=operator.itemgetter(0))
last_date = day_dict[len(day_dict) - 1]
last_action = False
for attendance_day in sorted_employee_dic:
day_dict = attendance_day[1]
for line in day_dict:
if line.attendance_status != 'sign_none':
if line.attendance_status == 'sign_in':
check_in = line.name
vals = {
'employee_id': line.employee_id.id,
'name': line.name,
'day': line.date,
'check_in':check_in,
}
hr_attendance = hr_attendance.search([('name','=', str(line.name)), ('employee_id','=',line.employee_id.id)])
if not hr_attendance:
if last_action != line.attendance_status:
created_rec = hr_attendance.create(vals)
_logger.info('Create Attendance '+ str(created_rec) +' for '+ str(line.employee_id.name)+' on ' + str(line.name))
elif line.attendance_status == 'sign_out':
check_out = line.name
hr_attendance_ids = hr_attendance.search([('employee_id','=',line.employee_id.id), ('day','=',line.date)])
if hr_attendance_ids:
for attend_id in hr_attendance_ids:
if attend_id.day == line.date and attend_id.check_in and not attend_id.check_out:
attend_id.write({'check_out':check_out})
_logger.info('Updated '+str(attend_id.day)+ "'s Attendance, "+str(line.employee_id.name)+ ' Checked Out at: '+ str(check_out))
else:
raise except_orm(_('Warning !'), _('Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in) at '+str(line.name)+' for '+str(line.employee_id.name)))
last_action = line.attendance_status
move_attendance_wizard()