@@ -15,10 +15,10 @@ class HrAttendance(models.Model):
|
||||
_rec_name = 'current_data'
|
||||
|
||||
is_clock_card = fields.Boolean(string="外勤")
|
||||
is_no_card = fields.Boolean(string="缺卡", groups_operator='count_false')
|
||||
is_early_card = fields.Boolean(string="早退", groups_operator='count_false')
|
||||
is_late_card = fields.Boolean(string="迟到", groups_operator='count_false')
|
||||
is_abnormal = fields.Boolean(string="异常", groups_operator='count_false')
|
||||
is_no_card = fields.Boolean(string="缺卡", group_operator='count_false')
|
||||
is_early_card = fields.Boolean(string="早退", group_operator='count_false')
|
||||
is_late_card = fields.Boolean(string="迟到", group_operator='count_false')
|
||||
is_abnormal = fields.Boolean(string="异常", group_operator='count_false')
|
||||
work_time_type = fields.Selection([('close_day', '休息日'), ('work_day', '工作日')], string="工作时间类型")
|
||||
company_id = fields.Many2one('res.company', string='公司', index=True, default=lambda self: self.env.company)
|
||||
on_card_location = fields.Char(string="上班打卡地点")
|
||||
|
||||
@@ -599,7 +599,7 @@ class HrAttendanceDetail(models.Model):
|
||||
:return:
|
||||
"""
|
||||
# 同步整理当天出勤数据
|
||||
attendance_obj = self.env['hr.attendance'].search([("userid", "=", user.id), ("current_data", "=", current_date)], limit=1)
|
||||
attendance_obj = self.env['hr.attendance'].search([("userid", "=", user.oauth_uid), ("current_data", "=", current_date)], limit=1)
|
||||
hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", user.id)], limit=1)
|
||||
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())
|
||||
@@ -608,15 +608,13 @@ class HrAttendanceDetail(models.Model):
|
||||
if not hr_employee_obj.default_planning_role_id:
|
||||
attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
'employee_id': hr_employee_obj.id,
|
||||
"userid": user.id,
|
||||
"userid": user.oauth_uid,
|
||||
"current_data": current_date,
|
||||
"attendance_type": "wx_work"
|
||||
})
|
||||
if attendance_obj.is_approval:
|
||||
# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
self._do_not_planning_role(user, current_date, attendance_obj)
|
||||
|
||||
else:
|
||||
return True # 暂时跳过
|
||||
planning_slot_id = self.env['planning.slot'].search(
|
||||
[('resource_id', '=', hr_employee_obj.resource_id.id),
|
||||
('start_datetime', '>=', current_datetime_start),
|
||||
@@ -625,28 +623,36 @@ class HrAttendanceDetail(models.Model):
|
||||
if planning_slot_id:
|
||||
attendance_obj = self.env['hr.attendance'].sudo().create({
|
||||
'employee_id': hr_employee_obj.id,
|
||||
"userid": user.id,
|
||||
"userid": user.oauth_uid,
|
||||
"current_data": current_date,
|
||||
"shift_id": planning_slot_id.id,
|
||||
"attendance_type": "wx_work"
|
||||
})
|
||||
if attendance_obj.is_approval:
|
||||
# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
self._do_planning_role(user, current_date, attendance_obj)
|
||||
else:
|
||||
# 没有排班
|
||||
return True
|
||||
if not hr_employee_obj.default_planning_role_id:
|
||||
if attendance_obj.is_approval:
|
||||
# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
self._do_not_planning_role(user, current_date, attendance_obj)
|
||||
else:
|
||||
return True # 暂时跳过
|
||||
if planning_slot_id:
|
||||
if attendance_obj.is_approval:
|
||||
# 已经审批修复无需再次进行更新数据
|
||||
return True
|
||||
self._do_planning_role(user, current_date, attendance_obj)
|
||||
|
||||
# 查询出当前抓取微信的当前时间的所有数据
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("userid", "=", user.id),
|
||||
("checkin_time", ">=", current_datetime_start),
|
||||
("checkin_time", "<=", current_datetime_end)])
|
||||
[("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_not_planning_role(self, user, current_date, attendance_obj):
|
||||
"""
|
||||
正常班次的 上班下班判断
|
||||
@@ -667,9 +673,9 @@ class HrAttendanceDetail(models.Model):
|
||||
# 判断打卡情况排除未打卡情况
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.id),
|
||||
("checkin_time", ">=", current_datetime_start),
|
||||
("checkin_time", "<=", current_datetime_end)])
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", current_datetime_start - timedelta(hours=8)),
|
||||
("checkin_time", "<=", current_datetime_end - timedelta(hours=8))])
|
||||
# 没有打卡记录说明缺卡
|
||||
if len(attendance_detail_obj) <= 0:
|
||||
attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True})
|
||||
@@ -677,59 +683,26 @@ class HrAttendanceDetail(models.Model):
|
||||
# 打了一次卡记录说明缺卡
|
||||
elif len(attendance_detail_obj) == 1:
|
||||
checkin_time = attendance_detail_obj.checkin_time
|
||||
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 attendance_detail_obj.checkin_type == "上班打卡":
|
||||
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,
|
||||
})
|
||||
elif attendance_detail_obj.checkin_type == "下班打卡":
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": will_datetime_end,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
"is_no_card": True,
|
||||
})
|
||||
else:
|
||||
# 如果是 打卡时间 早于 上班时间 判定为 上班打卡 缺下班卡
|
||||
if will_datetime_start > checkin_time:
|
||||
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,
|
||||
})
|
||||
# 如果是 打卡时间 晚于 下班时间 判定为 下班打卡 缺上班卡
|
||||
elif will_datetime_end < checkin_time:
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_out_time": will_datetime_end,
|
||||
"check_out": checkin_time,
|
||||
"is_early_card": will_datetime_end > checkin_time,
|
||||
"is_no_card": True,
|
||||
})
|
||||
# 既不是上班也不是下班,默认为上班打卡
|
||||
else:
|
||||
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,
|
||||
})
|
||||
will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
will_datetime_end = checkin_time.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,
|
||||
})
|
||||
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]
|
||||
# 最早 和 最晚 时间
|
||||
min_time = min(checkin_time_list)
|
||||
max_time = max(checkin_time_list)
|
||||
|
||||
# 赋值企业微信打卡数据
|
||||
will_datetime_start = min_time.replace(hour=min_hour, minute=min_minute)
|
||||
will_datetime_end = max_time.replace(hour=max_hour, minute=max_minute)
|
||||
will_datetime_start = min_time.replace(hour=min_hour, minute=min_minute) - timedelta(hours=8)
|
||||
will_datetime_end = max_time.replace(hour=max_hour, minute=max_minute) - timedelta(hours=8)
|
||||
# 查询最早时间上班时间 查询最晚下班时间
|
||||
attendance_obj.sudo().write({
|
||||
"sch_check_in_time": will_datetime_start,
|
||||
@@ -758,8 +731,8 @@ class HrAttendanceDetail(models.Model):
|
||||
hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", user.id)], limit=1)
|
||||
planning_id = self.env['planning.slot'].search(
|
||||
[('resource_id', '=', hr_employee_obj.resource_id.id),
|
||||
('start_datetime', '>=', current_datetime_start),
|
||||
('start_datetime', '<=', current_datetime_end)])
|
||||
('start_datetime', '>=', current_datetime_start - timedelta(hours=8)),
|
||||
('start_datetime', '<=', current_datetime_end - timedelta(hours=8))])
|
||||
|
||||
if planning_id:
|
||||
planning_start_time = planning_id.start_datetime + timedelta(hours=8)
|
||||
@@ -768,9 +741,9 @@ class HrAttendanceDetail(models.Model):
|
||||
# 判断打卡情况排除未打卡情况
|
||||
attendance_detail_obj = self.env['hr.attendance.detail'].sudo().search(
|
||||
[("exception_type", "!=", "未打卡"),
|
||||
("userid", "=", user.id),
|
||||
("checkin_time", ">=", planning_start_time),
|
||||
("checkin_time", "<=", planning_end_time)])
|
||||
("userid", "=", user.oauth_uid),
|
||||
("checkin_time", ">=", planning_start_time - timedelta(hours=8)),
|
||||
("checkin_time", "<=", planning_end_time - timedelta(hours=8))])
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user