From 642d2f138f01ab657c620300940eb8a4e45a30c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?=
<9664676+pengyuthon@user.noreply.gitee.com>
Date: Sun, 12 Oct 2025 18:32:17 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yuthon_hr_attendance/models/hr_attendance.py | 93 +++++++++++++------
.../models/hr_attendance_detail_wechat.py | 2 +-
.../views/hr_attendance_views.xml | 8 ++
3 files changed, 75 insertions(+), 28 deletions(-)
diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py
index 581c661f9..5e69ff1eb 100644
--- a/yuthon_hr_attendance/models/hr_attendance.py
+++ b/yuthon_hr_attendance/models/hr_attendance.py
@@ -314,36 +314,39 @@ class HrAttendance(models.Model):
# 判断是否为工作日
is_workday = self._process_shift_days(today)
for employee in all_employees:
- # 查找该员工当天的考勤记录
- employee_record = attend_records.filtered(
- lambda r: r.employee_id.id == employee.id
- )
+ # 白名单不做处理
+ resource_user_ids = employee.resource_calendar_id.resource_user_ids.ids
+ if employee.id not in resource_user_ids:
+ # 查找该员工当天的考勤记录
+ employee_record = attend_records.filtered(
+ lambda r: r.employee_id.id == employee.id
+ )
- # 工作日打卡情况判断
- if is_workday:
- if employee_record:
- is_no_card = (not employee_record.check_in or not employee_record.check_out) and (not employee_record.is_clock_card or not employee_record.is_workflow)
+ # 工作日打卡情况判断
+ if is_workday:
+ if employee_record:
+ is_no_card = (not employee_record.check_in or not employee_record.check_out) and (not employee_record.is_clock_card or not employee_record.is_workflow)
+ else:
+ is_no_card = True
else:
- is_no_card = True
- else:
- is_no_card = False
+ is_no_card = False
- if employee_record:
- # 更新现有记录的缺卡状态
- employee_record.write({'is_no_card': is_no_card})
- if is_no_card == True:
- employee_record.write({'absenteeism_card': True,
- 'is_abnormal': True
- })
- else:
- # 没有记录且需要标记为缺卡时,创建新记录
- self.env['hr.attendance'].create({
- 'employee_id': employee.id,
- 'current_data': today,
- 'is_no_card': is_no_card,
- 'check_in': False,
- 'check_out': False
- })
+ if employee_record:
+ # 更新现有记录的缺卡状态
+ employee_record.write({'is_no_card': is_no_card})
+ if is_no_card == True:
+ employee_record.write({'absenteeism_card': True,
+ 'is_abnormal': True
+ })
+ else:
+ # 没有记录且需要标记为缺卡时,创建新记录
+ self.env['hr.attendance'].create({
+ 'employee_id': employee.id,
+ 'current_data': today,
+ 'is_no_card': is_no_card,
+ 'check_in': False,
+ 'check_out': False
+ })
def _process_shift_days(self, current_data):
"""
@@ -429,6 +432,22 @@ class HrAttendance(models.Model):
title="打卡异常提醒", description="本月迟到: {}\n本月缺卡: {}\n本月早退: {}\n".format(is_late_card, is_no_card, is_early_card),
url=url, btntxt="详细信息")
+ def update_state(self):
+ attendance_ids = self.env["hr.attendance"].browse(
+ self._context.get('active_ids', self._context.get('active_id'))
+ )
+ for rec in attendance_ids:
+ rec.write({'is_no_card': False,
+ 'is_early_card': False,
+ 'shift_name': False,
+ 'is_holiday': False,
+ 'is_week': False,
+ 'is_late_card': False,
+ 'is_abnormal': False,
+ 'is_warning': False,
+ 'absenteeism_card': False
+ })
+
def button_controls_wizard(self):
return {
"type": "ir.actions.act_window",
@@ -1167,6 +1186,14 @@ class HrAttendance(models.Model):
if record.employee_id.resource_id in related_resources_set:
record.shift_name = '休息'
record.is_week = True
+ record.write({
+ 'is_early_card': False,
+ 'is_late_card': False,
+ 'is_abnormal': False,
+ 'is_warning': False,
+ 'is_no_card': False,
+ 'absenteeism_card': False,
+ })
continue
if record.current_data:
@@ -1208,6 +1235,18 @@ class HrAttendance(models.Model):
record.is_holiday = is_holiday
+ if record.employee_id.id in record.employee_id.resource_calendar_id.resource_user_ids.ids:
+ record.write({'is_no_card': False,
+ 'is_early_card': False,
+ 'shift_name':False,
+ 'is_holiday':False,
+ 'is_week':False,
+ 'is_late_card': False,
+ 'is_abnormal': False,
+ 'is_warning': False,
+ 'absenteeism_card': False
+ })
+
@api.model
def create(self, vals):
record = super(HrAttendance, self).create(vals)
diff --git a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
index 94bee2ecb..60d5c5788 100644
--- a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
+++ b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
@@ -366,7 +366,7 @@ class HrAttendanceDetail(models.Model):
employee_list.append(resource_id.employee_id.id)
if employee.id not in employee_list:
# 判断是否工作日
- if not self._process_shift_days(current_data):
+ if self._process_shift_days(current_data):
return is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card, is_no_card
is_tianhe_property = employee.company_id.name == "天河物管"
diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml
index 3aa6821b5..15c970d36 100644
--- a/yuthon_hr_attendance/views/hr_attendance_views.xml
+++ b/yuthon_hr_attendance/views/hr_attendance_views.xml
@@ -178,6 +178,14 @@
code
+
+ 初始化状态
+
+
+ code
+ action = model.update_state()
+
+
批量更新班次名称