添加功能
This commit is contained in:
@@ -244,119 +244,119 @@ class HrAttendanceDetail(models.Model):
|
||||
if not attendance_obj:
|
||||
res_user_obj = self.env['res.users'].search([("oauth_uid", "=", userid)], limit=1)
|
||||
hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", res_user_obj.id)], limit=1)
|
||||
attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
'employee_id': hr_employee_obj.id,
|
||||
"userid": userid,
|
||||
"current_data": current_data,
|
||||
"attendance_type": "wx_work"
|
||||
})
|
||||
# 获取考勤日历的上班下班时间
|
||||
min_hour_from = self.env['resource.calendar'].search([])[0].attendance_ids[0].hour_from
|
||||
min_hour = int(min_hour_from)
|
||||
min_minute = int(min_hour_from * 10 % min_hour_from)
|
||||
max_hour_to = self.env['resource.calendar'].search([])[-1].attendance_ids[0].hour_to
|
||||
max_hour = int(max_hour_to)
|
||||
max_minute = int(max_hour_to * 10 % max_hour_to)
|
||||
if attendance_obj.is_approval:
|
||||
# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
# 赋值企业微信打卡数据
|
||||
attendance_obj.attendance_type = "wx_work"
|
||||
checkin_type = data.get("checkin_type", "")
|
||||
exception_type = data.get("exception_type", "")
|
||||
will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute)
|
||||
will_datetime_end = checkin_time.replace(hour=max_hour, minute=max_minute)
|
||||
if not hr_employee_obj.default_planning_role_id:
|
||||
if exception_type != "未打卡":
|
||||
if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif attendance_obj.is_early_card or attendance_obj.is_late_card:
|
||||
attendance_obj.sudo().write({"is_abnormal": True})
|
||||
else:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
elif hr_employee_obj.default_planning_role_id.name == '保安部':
|
||||
current_datetime_start = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.min)
|
||||
current_datetime_end = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.max)
|
||||
planning_slot_id = self.env['planning.slot'].search([('resource_id', '=', hr_employee_obj.resource_id.id),
|
||||
('start_datetime', '>=', current_datetime_start),
|
||||
('start_datetime', '<=', current_datetime_end)])
|
||||
if planning_slot_id:
|
||||
checkin_type = data.get("checkin_type", "")
|
||||
exception_type = data.get("exception_type", "")
|
||||
if not hr_employee_obj.default_planning_role_id:
|
||||
attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
'employee_id': hr_employee_obj.id,
|
||||
"userid": userid,
|
||||
"current_data": current_data,
|
||||
"shift_id": planning_slot_id.id,
|
||||
"attendance_type": "wx_work"
|
||||
})
|
||||
if checkin_time:
|
||||
if checkin_time and checkin_type == "上班打卡" and not attendance_obj.check_in:
|
||||
|
||||
# 获取考勤日历的上班下班时间
|
||||
min_hour_from = self.env['resource.calendar'].search([])[0].attendance_ids[0].hour_from
|
||||
min_hour = int(min_hour_from)
|
||||
min_minute = int(min_hour_from * 10 % min_hour_from)
|
||||
max_hour_to = self.env['resource.calendar'].search([])[-1].attendance_ids[0].hour_to
|
||||
max_hour = int(max_hour_to)
|
||||
max_minute = int(max_hour_to * 10 % max_hour_to)
|
||||
if attendance_obj.is_approval:# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
# 赋值企业微信打卡数据
|
||||
attendance_obj.attendance_type = "wx_work"
|
||||
will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute)
|
||||
will_datetime_end = checkin_time.replace(hour=max_hour, minute=max_minute)
|
||||
if exception_type != "未打卡":
|
||||
if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif checkin_time and checkin_type == "下班打卡" and not attendance_obj.check_out:
|
||||
elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and checkin_time < attendance_obj.check_in:
|
||||
elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and checkin_time > attendance_obj.check_out:
|
||||
elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif checkin_time and not attendance_obj.check_in and not attendance_obj.check_out:
|
||||
elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": sch_checkin_time,
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
"is_late_card": checkin_time > will_datetime_start,
|
||||
})
|
||||
elif checkin_time and attendance_obj.check_in and not attendance_obj.check_out:
|
||||
elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": sch_checkin_time,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
})
|
||||
elif attendance_obj.is_early_card or attendance_obj.is_late_card:
|
||||
attendance_obj.sudo().write({"is_abnormal": True})
|
||||
else:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
elif hr_employee_obj.default_planning_role_id.name == '保安部':
|
||||
current_datetime_start = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.min)
|
||||
current_datetime_end = datetime.datetime.combine(datetime.datetime.strptime(current_data, '%Y-%m-%d'), datetime.time.max)
|
||||
planning_slot_id = self.env['planning.slot'].search([('resource_id', '=', hr_employee_obj.resource_id.id),
|
||||
('start_datetime', '>=', current_datetime_start),
|
||||
('start_datetime', '<=', current_datetime_end)])
|
||||
if planning_slot_id:
|
||||
attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
'employee_id': hr_employee_obj.id,
|
||||
"userid": userid,
|
||||
"current_data": current_data,
|
||||
"shift_id": planning_slot_id.id,
|
||||
"attendance_type": "wx_work"
|
||||
})
|
||||
if checkin_time:
|
||||
if checkin_time and checkin_type == "上班打卡" and not attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
})
|
||||
elif checkin_time and checkin_type == "下班打卡" and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
})
|
||||
elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and checkin_time < attendance_obj.check_in:
|
||||
attendance_obj.sudo().write({
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
})
|
||||
elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and checkin_time > attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
})
|
||||
elif checkin_time and not attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"check_in": checkin_time,
|
||||
"is_late_card": checkin_time > planning_slot_id.start_datetime,
|
||||
})
|
||||
elif checkin_time and attendance_obj.check_in and not attendance_obj.check_out:
|
||||
attendance_obj.sudo().write({
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": planning_slot_id.end_datetime > checkin_time,
|
||||
})
|
||||
elif attendance_obj.is_early_card or attendance_obj.is_late_card:
|
||||
attendance_obj.sudo().write({"is_abnormal": True})
|
||||
else:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
# elif planning_slot_id.department_id.name == '工程部':
|
||||
# attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
# 'employee_id': hr_employee_obj.id,
|
||||
|
||||
Reference in New Issue
Block a user