添加功能

This commit is contained in:
zhouzhou
2024-12-17 21:17:43 +08:00
parent 302893f624
commit 66ce4e1695
+342 -42
View File
@@ -266,51 +266,351 @@ class HrAttendanceDetail(models.Model):
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 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})
if 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})
else:
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
# 进行关联
current_datetime_start = datetime.datetime.combine(current_data, datetime.time.min)
current_datetime_end = datetime.datetime.combine(current_data, 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:
if planning_slot_id.department_id.name == '保安部':
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 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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
elif attendance_obj.is_early_card or attendance_obj.is_late_card:
attendance_obj.sudo().write({"is_abnormal": True})
elif planning_slot_id.department_id.name == '工程部':
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 planning_slot_id.template_id.planning_name == '中值':
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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
elif datetime.time(11, 30)<= checkin_time <= datetime.time(13, 30):
attendance_obj.sudo().write({
"sch_check_out_time": sch_checkin_time,
"check_out": checkin_time,
"noon_duty":False
})
elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty:
attendance_obj.sudo().write({"is_abnormal": True})
else:
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
elif planning_slot_id.template_id.planning_name == '夜值':
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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or
datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)):
attendance_obj.sudo().write({
"sch_check_out_time": sch_checkin_time,
"check_out": checkin_time,
"night_duty": False
})
elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.night_duty:
attendance_obj.sudo().write({"is_abnormal": True})
else:
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
else:
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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty:
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,
"userid": userid,
"current_data": current_data,
"shift_id": planning_slot_id.id,
"attendance_type": "wx_work"
})
if planning_slot_id.template_id.planning_name == '夜值':
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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
elif (datetime.time(9, 30) <= checkin_time <= datetime.time(23, 59, 59) or
datetime.time(0, 0) <= checkin_time <= datetime.time(6, 0)):
attendance_obj.sudo().write({
"sch_check_out_time": sch_checkin_time,
"check_out": checkin_time,
"night_duty": False
})
elif attendance_obj.is_early_card or attendance_obj.is_late_card or attendance_obj.noon_duty:
attendance_obj.sudo().write({"is_abnormal": True})
else:
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
else:
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,
})
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,
})
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,
})
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,
})
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,
})
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,
})
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})
# 进行关联
attendance_detail_obj.hr_attendance_id = attendance_obj.id
return True
def get_hr_attendance_time(self):
"""
获取企业微信打卡数据的核心逻辑