-
Change
-
解决结果: 完成
-
Medium
-
无
-
无
-
Y-易路产品-
-
linqingxuan
-
时间管理
考勤工时的计算公式如下:
result = {}
attendance_period = pre_data['attendance_period']
day_types_without_schedule = pre_data['day_types_without_schedule']
for employee_id in employee_ids:
employee_periods = attendance_period.get(employee_id, {})
employee_days_type = day_types_without_schedule.get(employee_id, {})
fmt='%Y-%m-%d'
result[employee_id] = {}
attendance_hours = 0
for attendance_date, day_periods in employee_periods.items():
for day_calendar_id, period in day_periods.items():
if not period['day_type']:
continue
- 标准工时员工工作日考勤
if period['day_type'] == 'workday':
attendance_hours += period['attendance_hours'] - 排班工作日考勤
elif period['day_type'] == 'schedule_workday': - 排班考勤跨天
if period['clock_in_time'] and period['clock_out_time'] and period['clock_in_time'][0:10]<period['clock_out_time'][0:10]:
year_1, month_1, day_1 = time.strptime(period['clock_out_time'][0:10], fmt)[:3]
year_2, month_2, day_2 = time.strptime(period['clock_in_time'][0:10], fmt)[:3] - 签入签出都在法定节假日
if employee_days_type.get(datetime.date(year_1, month_1, day_1 )) in ['statutory_holiday'] and employee_days_type.get(datetime.date(year_2, month_2, day_2))in ['statutory_holiday']:
continue - 签入时间在法定节假日,签出时间不在法定节假日
elif employee_days_type.get(datetime.date(year_2, month_2, day_2)) in ['statutory_holiday'] and employee_days_type.get(datetime.date(year_1, month_1, day_1 )) not in ['statutory_holiday']:
clock_in_str = '%s 00:00:00'% period['clock_out_time'][0:10]
clock_in = datetime.datetime.strptime(clock_in_str, '%Y-%m-%d %H:%M:%S')
clock_out = datetime.datetime.strptime(period['clock_out_time'][0:19],
'%Y-%m-%d %H:%M:%S')
clock_buckets = TimeBucketMulti([TimeBucket(clock_in, clock_out)])
attendance_hours += round(clock_buckets.total_seconds() / 3600.0, 2)
- 签入时间不在法定节假日,签出时间在法定节假日
elif employee_days_type.get(datetime.date(year_2, month_2, day_2)) not in ['statutory_holiday'] and employee_days_type.get(datetime.date(year_1, month_1, day_1 )) in ['statutory_holiday']:
clock_in = datetime.datetime.strptime(period['clock_in_time'][0:19], '%Y-%m-%d %H:%M:%S')
clock_out_str = '%s 23:59:59' % period['clock_in_time'][0:10]
clock_out = datetime.datetime.strptime(clock_out_str, '%Y-%m-%d %H:%M:%S')
clock_buckets = TimeBucketMulti([TimeBucket(clock_in, clock_out)])
attendance_hours += round(clock_buckets.total_seconds() / 3600.0, 2)
- 签入签出都不在法定节假日
elif employee_days_type.get(datetime.date(year_1, month_1, day_1 )) not in ['statutory_holiday'] and employee_days_type.get(datetime.date(year_2, month_2, day_2)) not in ['statutory_holiday']:
attendance_hours += period['attendance_hours']
- 没有跨天
else:
for day in employee_days_type:
if employee_days_type.get(day) != 'statutory_holiday' and day.strftime('%Y-%m-%d') == period['attendance_date']:
attendance_hours += period['attendance_hours']
else:
continue
else:
continue
result[employee_id] = attendance_hours