行政班次也使用区间, 请先测试
This commit is contained in:
@@ -620,13 +620,13 @@ class HrAttendanceDetail(models.Model):
|
||||
return True
|
||||
self._do_not_planning_role(user, current_date, attendance_obj)
|
||||
|
||||
# 查询出当前抓取微信的当前时间的所有数据
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", current_datetime_start - timedelta(hours=8)),
|
||||
("checkin_time", "<=", current_datetime_end - timedelta(hours=8))])
|
||||
# 关联 打卡详情
|
||||
attendance_detail_obj.hr_attendance_id = attendance_obj.id
|
||||
# # 查询出当前抓取微信的当前时间的所有数据
|
||||
# attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
# [("userid", "=", user.oauth_uid),
|
||||
# ("checkin_time", ">=", current_datetime_start - timedelta(hours=8)),
|
||||
# ("checkin_time", "<=", current_datetime_end - timedelta(hours=8))])
|
||||
# # 关联 打卡详情
|
||||
# attendance_detail_obj.hr_attendance_id = attendance_obj.id
|
||||
return True
|
||||
|
||||
def _do_plan_save_wx_attendance_data(self, user, current_date):
|
||||
@@ -685,51 +685,75 @@ class HrAttendanceDetail(models.Model):
|
||||
max_hour_to = self.env['resource.calendar'].search([])[0].attendance_ids[-1].hour_to
|
||||
max_hour = int(max_hour_to)
|
||||
max_minute = int(max_hour_to * 10 % max_hour_to)
|
||||
will_datetime_start = current_datetime_start.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
will_datetime_end = current_datetime_end.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8)
|
||||
# 判断打卡情况排除未打卡情况
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
# 6:00 - 17:00 // 10.00 - // 5.00。
|
||||
# 改为区间打卡
|
||||
check_in_start = datetime.strptime(str(current_date) + " " + "06:00", "%Y-%m-%d %H:%M") - timedelta(hours=8)
|
||||
check_in_end = datetime.strptime(str(current_date) + " " + "17:00", "%Y-%m-%d %H:%M") - timedelta(hours=8)
|
||||
check_out_start = datetime.strptime(str(current_date) + " " + "10:00", "%Y-%m-%d %H:%M") - timedelta(hours=8)
|
||||
check_out_end = datetime.strptime(str(current_date) + " " + "05:00", "%Y-%m-%d %H:%M") + relativedelta(days=1) - timedelta(hours=8)
|
||||
|
||||
# 上班
|
||||
attendance_detail_obj_in = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", current_datetime_start - timedelta(hours=8)),
|
||||
("checkin_time", "<=", current_datetime_end - timedelta(hours=8))])
|
||||
("checkin_time", ">=", check_in_start),
|
||||
("checkin_time", "<=", check_in_end)])
|
||||
# 关联 打卡详情
|
||||
attendance_detail_obj_in.hr_attendance_id = attendance_obj.id
|
||||
# 没有打卡记录说明缺卡
|
||||
if len(attendance_detail_obj) <= 0:
|
||||
if len(attendance_detail_obj_in) <= 0:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
return True
|
||||
# 打了一次卡记录说明缺卡
|
||||
elif len(attendance_detail_obj) == 1:
|
||||
checkin_time = attendance_detail_obj.checkin_time
|
||||
will_datetime_start = current_datetime_start.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
will_datetime_end = current_datetime_end.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8)
|
||||
# 既不是上班也不是下班,默认为上班打卡
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": will_datetime_start,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
"is_no_card": True,
|
||||
"is_abnormal": True,
|
||||
})
|
||||
return True
|
||||
else:
|
||||
# 多次打卡时间的集合
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj]
|
||||
# 最早 和 最晚 时间
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_in]
|
||||
# 最早 时间
|
||||
min_time = min(checkin_time_list)
|
||||
max_time = max(checkin_time_list)
|
||||
|
||||
# 赋值企业微信打卡数据
|
||||
will_datetime_start = current_datetime_start.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
will_datetime_end = current_datetime_end.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8)
|
||||
# 查询最早时间上班时间 查询最晚下班时间
|
||||
attendance_obj.sudo().write({
|
||||
"is_no_card": False,
|
||||
"sch_check_in_time": will_datetime_start,
|
||||
"check_in": min_time,
|
||||
"is_late_card": min_time > will_datetime_start,
|
||||
"sch_check_out_time": will_datetime_end,
|
||||
"check_out": max_time,
|
||||
"is_early_card": will_datetime_end > max_time,
|
||||
"is_abnormal": min_time > will_datetime_start or will_datetime_end > max_time,
|
||||
"is_no_card": False,
|
||||
"is_abnormal": False,
|
||||
})
|
||||
# 下班
|
||||
attendance_detail_obj_out = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", check_out_start),
|
||||
("checkin_time", "<=", check_out_end),
|
||||
])
|
||||
# 关联 打卡详情
|
||||
attendance_detail_obj_out.hr_attendance_id = attendance_obj.id
|
||||
|
||||
if len(attendance_detail_obj_out) <= 0:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
# 打了一次卡记录说明缺卡
|
||||
else:
|
||||
# 多次打卡时间的集合
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_out]
|
||||
# 最早 时间
|
||||
max_time = max(checkin_time_list)
|
||||
# 如果上班没有打卡
|
||||
if not attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": will_datetime_start,
|
||||
"check_in": max_time,
|
||||
"is_late_card": max_time < will_datetime_start,
|
||||
"is_no_card": True,
|
||||
"is_abnormal": True,
|
||||
})
|
||||
else:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": will_datetime_end,
|
||||
"check_out": max_time,
|
||||
"is_late_card": max_time < will_datetime_end,
|
||||
"is_no_card": False,
|
||||
"is_abnormal": False,
|
||||
})
|
||||
return True
|
||||
|
||||
def _do_planning_role(self, user, current_date, attendance_obj, planning_id):
|
||||
@@ -788,21 +812,21 @@ class HrAttendanceDetail(models.Model):
|
||||
|
||||
# 判断打卡情况排除未打卡情况
|
||||
# 上班
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
attendance_detail_obj_in = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", check_in_start),
|
||||
("checkin_time", "<=", check_in_end),
|
||||
])
|
||||
# 关联 打卡详情
|
||||
attendance_detail_obj.hr_attendance_id = attendance_obj.id
|
||||
attendance_detail_obj_in.hr_attendance_id = attendance_obj.id
|
||||
|
||||
if len(attendance_detail_obj) <= 0:
|
||||
if len(attendance_detail_obj_in) <= 0:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
# 打了一次卡记录说明缺卡
|
||||
else:
|
||||
# 多次打卡时间的集合
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj]
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_in]
|
||||
# 最早 时间
|
||||
min_time = min(checkin_time_list)
|
||||
attendance_obj.sudo().write({
|
||||
@@ -814,21 +838,21 @@ class HrAttendanceDetail(models.Model):
|
||||
})
|
||||
|
||||
# 下班
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
attendance_detail_obj_out = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", check_out_start),
|
||||
("checkin_time", "<=", check_out_end),
|
||||
])
|
||||
# 关联 打卡详情
|
||||
attendance_detail_obj.hr_attendance_id = attendance_obj.id
|
||||
attendance_detail_obj_out.hr_attendance_id = attendance_obj.id
|
||||
|
||||
if len(attendance_detail_obj) <= 0:
|
||||
if len(attendance_detail_obj_out) <= 0:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
# 打了一次卡记录说明缺卡
|
||||
else:
|
||||
# 多次打卡时间的集合
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj]
|
||||
checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_out]
|
||||
# 最早 时间
|
||||
max_time = max(checkin_time_list)
|
||||
# 如果上班没有打卡
|
||||
|
||||
Reference in New Issue
Block a user