diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py
index 75b966e54..1a8e51418 100644
--- a/yuthon_hr_attendance/models/hr_attendance.py
+++ b/yuthon_hr_attendance/models/hr_attendance.py
@@ -794,24 +794,6 @@ class HrAttendance(models.Model):
title="打卡提醒",
url=url, btntxt="详细信息")
- def update_shift(self):
- target_date = fields.Date.to_date('2025-8-20')
- target_records = self.search([
- ('current_data ', '=', target_date),
- ])
- employee_groups = {}
- for record in target_records:
- emp_id = record.employee_id.id
- if emp_id not in employee_groups:
- employee_groups[emp_id] = []
- employee_groups[emp_id].append(record)
- deleted_count = 0
- for emp_id, records in employee_groups.items():
- if len(records) > 1:
- records_to_delete = records[1:]
- records_to_delete.unlink()
- deleted_count += len(records_to_delete)
-
def update_id(self):
attendance_ids = self.env["hr.attendance"].browse(
self._context.get('active_ids', self._context.get('active_id')))
diff --git a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
index fc6ef0fa1..801338a7e 100644
--- a/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
+++ b/yuthon_hr_attendance/models/hr_attendance_detail_wechat.py
@@ -85,15 +85,40 @@ class HrAttendanceDetail(models.Model):
@api.model
def create(self, vals):
record = super(HrAttendanceDetail, self).create(vals)
- if record.employee_id and record.checkin_time and record.checkin_type != '未打卡':
+ if record.employee_id and record.checkin_time:
self._update_actual_attendance(record)
self._sync_to_hr_attendance(record)
_logger.info(f"{record.employee_id.name}--------")
return record
def _update_actual_attendance(self, record):
- """更新假期日志中的实到天数"""
+ """更新假期日志中的实到天数和应到天数"""
+ should_days = 0
+
+
checkin_date = fields.Date.from_string(record.checkin_time)
+ month_start = datetime(checkin_date.year, checkin_date.month, 1).date()
+ if checkin_date.month == 12:
+ month_end = datetime(checkin_date.year, 12, 31).date()
+ else:
+ month_end = datetime(checkin_date.year, checkin_date.month + 1, 1).date() - timedelta(days=1)
+
+ slot_start_dt = datetime.combine(month_start, datetime.min.time())
+ slot_end_dt = datetime.combine(month_end, datetime.max.time())
+ employee_list = []
+ role_ids = self.env['planning.role'].search([('name', 'not in', ['厨卫(集团)', '项目运营岗'])])
+ for role in role_ids:
+ for resource_id in role.resource_ids:
+ employee_list.append(resource_id.employee_id.id)
+ if not record.employee_id.id in employee_list:
+ days = self.env['yuthon.vacation.reports']._create_leave_record(slot_start_dt, slot_end_dt)
+ else:
+ monthly_slots = self.env['planning.slot'].search([
+ ('employee_id', '=', record.employee_id.id),
+ ('start_datetime', '>=', slot_start_dt),
+ ('start_datetime', '<=', slot_end_dt)
+ ])
+ days = len(monthly_slots)
vacation_report = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', record.employee_id.id),
('vacation_date', '>=', fields.Date.to_string(date(checkin_date.year, checkin_date.month, 1))),
@@ -109,6 +134,7 @@ class HrAttendanceDetail(models.Model):
# 如果当天没有其他打卡记录,则实到天数+1
if not existing_checkins:
vacation_report.actual_attendance = (vacation_report.actual_attendance or 0) + 1
+ vacation_report.should_attendance = days
def _sync_to_hr_attendance(self, record):
"""同步打卡记录到hr.attendance 更新上下班打卡时间 """
@@ -154,7 +180,26 @@ class HrAttendanceDetail(models.Model):
template_domain.append(('department_id', 'in', all_dept_ids))
template = self.env['planning.slot.template'].search(template_domain, limit=1)
if not template:
- template = self.env['planning.slot.template'].search([('role_id.name', '=', '集团行政')], limit=1)
+ role_templates = [
+ {'role_name': '厨卫(集团)', 'template': None},
+ {'role_name': '项目运营岗', 'template': None}
+ ]
+
+ for item in role_templates:
+ item['template'] = self.env['planning.slot.template'].search([('role_id.name', '=', item['role_name'])],)
+
+ for item in role_templates:
+ if item['template']:
+ employee_ids = item['template'].role_id.resource_ids.employee_id.ids or []
+ employee_list = list(employee_ids)
+ if employee.id in employee_list:
+ template = item['template']
+ break
+ if not template:
+ template = self.env['planning.slot.template'].search(
+ [('role_id.name', '=', '集团行政')],
+ limit=1
+ )
next_day = current_data + timedelta(days=1)
start_datetime = datetime.combine(current_data, datetime.min.time()) - timedelta(hours=8)
# 判断是否需要包含次日记录
@@ -283,8 +328,14 @@ class HrAttendanceDetail(models.Model):
is_warning = False
absenteeism_card = False
- # 判断是否工作日
- if employee.company_id.name == "集团本部":
+ # 判断是否是行政班次
+ employee_list = []
+ role_ids = self.env['planning.role'].search([('name', 'not in', ['厨卫(集团)', '项目运营岗'])])
+ for role in role_ids:
+ for resource_id in role.resource_ids:
+ employee_list.append(resource_id.employee_id.id)
+ if employee.id not in employee_list:
+ # 判断是否工作日
if not self._process_shift_days(current_data):
return is_no_card, is_early_card, is_late_card, is_abnormal, is_warning, absenteeism_card
diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
index 605330c4a..689e8af02 100644
--- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py
+++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py
@@ -51,7 +51,7 @@ class YuthonVacationReports(models.Model):
right_days = fields.Float(string='转正天数', group_operator=None)
internship_days = fields.Float(string='实习天数', group_operator=None)
- should_attendance = fields.Integer(string="应到", compute='_compute_attendance_fields', store=True, group_operator=None)
+ should_attendance = fields.Integer(string="应到", store=True, group_operator=None)
actual_attendance = fields.Integer(string="实到", compute='_compute_attendance_fields', store=True,group_operator=None)
is_late_card = fields.Integer(string="迟到", compute='_compute_attendance_fields', store=True, group_operator=None)
diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml
index 0192090f5..56eb3e181 100644
--- a/yuthon_hr_attendance/views/hr_attendance_views.xml
+++ b/yuthon_hr_attendance/views/hr_attendance_views.xml
@@ -171,11 +171,4 @@
code
action = model.update_id()
-
- 测试删除
-
-
- code
- action = model.update_attendance()
-