diff --git a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py index f6d7b257c..b3eab31a7 100644 --- a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py +++ b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py @@ -392,6 +392,9 @@ class HrAttendanceDetail(models.Model): current_datetime_start = datetime.combine(datetime.strptime(current_date, '%Y-%m-%d'), datetime.min.time()) current_datetime_end = datetime.combine(datetime.strptime(current_date, '%Y-%m-%d'), datetime.max.time()) hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", user.id)], limit=1) + # 白名单 + resource_user_ids = hr_employee_obj.resource_calendar_id.resource_user_ids.ids + is_resource_user = True if hr_employee_obj.id in resource_user_ids else False # 判断是否是星期 tz = hr_employee_obj.resource_calendar_id.tz current_year = current_date.split('-')[0] @@ -435,52 +438,68 @@ class HrAttendanceDetail(models.Model): ("checkin_time", "<=", check_in_end)]) # 关联 打卡详情 attendance_detail_obj_in.hr_attendance_id = attendance_obj.id - # 没有打卡记录说明缺卡 - if len(attendance_detail_obj_in) <= 0: - attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) + # 白名单用户直接正常 + if is_resource_user: + if len(attendance_detail_obj_in) > 0: + # 多次打卡时间的集合 + checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_in] + # 最早 时间 + min_time = min(checkin_time_list) + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": min_time, + "is_late_card": False, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": False, + }) else: - # 多次打卡时间的集合 - checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_in] - # 最早 时间 - min_time = min(checkin_time_list) - # 查询最早时间上班时间 查询最晚下班时间 - # 判断时间 在10分钟内说明是 异常 - if will_datetime_start + timedelta(minutes=10) > min_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": min_time, - "is_late_card": False, - "is_no_card": False, - "is_abnormal": True, - "absenteeism_card": False, - }) - elif will_datetime_start + timedelta(hours=1) > min_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": min_time, - "is_late_card": True, - "is_no_card": False, - "is_abnormal": False, - "absenteeism_card": False, - }) - elif min_time > will_datetime_start + timedelta(hours=1) and min_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": min_time, - "is_late_card": False, - "is_no_card": False, - "is_abnormal": False, - "absenteeism_card": True, - }) + # 没有打卡记录说明缺卡 + if len(attendance_detail_obj_in) <= 0: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) else: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": min_time, - "is_late_card": min_time > will_datetime_start, - "is_no_card": False, - "is_abnormal": False, - "absenteeism_card": False, - }) + # 多次打卡时间的集合 + checkin_time_list = [obj.checkin_time for obj in attendance_detail_obj_in] + # 最早 时间 + min_time = min(checkin_time_list) + # 查询最早时间上班时间 查询最晚下班时间 + # 判断时间 在10分钟内说明是 异常 + if will_datetime_start + timedelta(minutes=10) > min_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": min_time, + "is_late_card": False, + "is_no_card": False, + "is_abnormal": True, + "absenteeism_card": False, + }) + elif will_datetime_start + timedelta(hours=1) > min_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": min_time, + "is_late_card": True, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": False, + }) + elif min_time > will_datetime_start + timedelta(hours=1) and min_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": min_time, + "is_late_card": False, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": True, + }) + else: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": min_time, + "is_late_card": min_time > will_datetime_start, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": False, + }) # 下班 attendance_detail_obj_out = self.env['hr.attendance.detail'].sudo().search( [("exception_type", "!=", "未打卡"), @@ -490,94 +509,120 @@ class HrAttendanceDetail(models.Model): ]) # 关联 打卡详情 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, "absenteeism_card": True}) - # 打了一次卡记录说明缺卡 - else: + # 白名单用户直接正常 + if is_resource_user: # 多次打卡时间的集合 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: - if will_datetime_start + timedelta(minutes=10) > max_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": max_time, - "is_late_card": False, - "is_no_card": True, - "is_abnormal": True, - "absenteeism_card": True, - }) - elif will_datetime_start + timedelta(hours=1) > max_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": max_time, - "is_late_card": True, - "is_no_card": True, - "is_abnormal": True, - "absenteeism_card": True, - }) - elif max_time > will_datetime_start + timedelta(hours=1) and max_time > will_datetime_start: - attendance_obj.sudo().write({ - "sch_check_in_time": will_datetime_start, - "check_in": max_time, - "is_late_card": False, - "is_no_card": True, - "is_abnormal": True, - "absenteeism_card": True, - }) - else: - 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, - "absenteeism_card": True, - }) - - # 如果上班时间早于下班时间说明下班的卡没打 - elif attendance_obj.check_in >= max_time: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": max_time, + "is_late_card": False, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": False, + }) + # 如果上班时间早于下班时间说明 + elif attendance_obj.check_in and attendance_obj.check_in < max_time: + attendance_obj.sudo().write({ + "sch_check_out_time": will_datetime_end, + "check_out": max_time, + "is_early_card": False, + "is_no_card": False, + "is_abnormal": False, + "absenteeism_card": False, + }) + else: + if len(attendance_detail_obj_out) <= 0: attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True, "absenteeism_card": True}) + # 打了一次卡记录说明缺卡 else: - if will_datetime_end - timedelta(minutes=10) < max_time < will_datetime_end: - attendance_obj.sudo().write({ - "sch_check_out_time": will_datetime_end, - "check_out": max_time, - "is_early_card": False, - "is_no_card": False, - "is_abnormal": True, - # "absenteeism_card": False, - }) - elif will_datetime_end - timedelta(hours=1) < max_time < will_datetime_end: - attendance_obj.sudo().write({ - "sch_check_out_time": will_datetime_end, - "check_out": max_time, - "is_early_card": True, - "is_no_card": False, - # "is_abnormal": False, - # "absenteeism_card": False, - }) - elif max_time < will_datetime_end - timedelta(hours=1): - attendance_obj.sudo().write({ - "sch_check_out_time": will_datetime_end, - "check_out": max_time, - "is_early_card": False, - "is_no_card": False, - # "is_abnormal": False, - "absenteeism_card": True, - }) + # 多次打卡时间的集合 + 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: + if will_datetime_start + timedelta(minutes=10) > max_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": max_time, + "is_late_card": False, + "is_no_card": True, + "is_abnormal": True, + "absenteeism_card": True, + }) + elif will_datetime_start + timedelta(hours=1) > max_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": max_time, + "is_late_card": True, + "is_no_card": True, + "is_abnormal": True, + "absenteeism_card": True, + }) + elif max_time > will_datetime_start + timedelta(hours=1) and max_time > will_datetime_start: + attendance_obj.sudo().write({ + "sch_check_in_time": will_datetime_start, + "check_in": max_time, + "is_late_card": False, + "is_no_card": True, + "is_abnormal": True, + "absenteeism_card": True, + }) + else: + 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, + "absenteeism_card": True, + }) + + # 如果上班时间早于下班时间说明下班的卡没打 + elif attendance_obj.check_in >= max_time: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True, "absenteeism_card": True}) else: - attendance_obj.sudo().write({ - "sch_check_out_time": will_datetime_end, - "check_out": max_time, - "is_early_card": max_time < will_datetime_end, - "is_no_card": False, - # "is_abnormal": False, - # "absenteeism_card": False, - }) + if will_datetime_end - timedelta(minutes=10) < max_time < will_datetime_end: + attendance_obj.sudo().write({ + "sch_check_out_time": will_datetime_end, + "check_out": max_time, + "is_early_card": False, + "is_no_card": False, + "is_abnormal": True, + # "absenteeism_card": False, + }) + elif will_datetime_end - timedelta(hours=1) < max_time < will_datetime_end: + attendance_obj.sudo().write({ + "sch_check_out_time": will_datetime_end, + "check_out": max_time, + "is_early_card": True, + "is_no_card": False, + # "is_abnormal": False, + # "absenteeism_card": False, + }) + elif max_time < will_datetime_end - timedelta(hours=1): + attendance_obj.sudo().write({ + "sch_check_out_time": will_datetime_end, + "check_out": max_time, + "is_early_card": False, + "is_no_card": False, + # "is_abnormal": False, + "absenteeism_card": True, + }) + else: + attendance_obj.sudo().write({ + "sch_check_out_time": will_datetime_end, + "check_out": max_time, + "is_early_card": max_time < will_datetime_end, + "is_no_card": False, + # "is_abnormal": False, + # "absenteeism_card": False, + }) return True def _do_planning_role(self, user, current_date, attendance_obj, planning_id):