From 63fec9502ee6dd42afa18c6bd6b65a7005f48b2d 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, 22 Feb 2026 18:33:54 +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 --- .../models/yuthon_vacation_reports.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 5180475af..f5215e3f9 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -720,6 +720,7 @@ class YuthonVacationReports(models.Model): probation_days = 0 # 试用期天数 regular_days = 0 # 转正天数 actual_attendance = 0 # 实到天数 = 应到天数 - 请假总天数 - 异常天数 + leave_total_days = 0 # 累计请假天数 is_retired = rec.employee_id.user_state in ('leave', 'withdraw') if rec.employee_id and rec.vacation_date and not is_retired: year = rec.vacation_date.year @@ -740,15 +741,35 @@ class YuthonVacationReports(models.Model): ]) if attendances: + # 1. 过滤有效考勤:仅排除休息/异常,保留请假记录 valid_attendances = [ att for att in attendances if (att.check_in or att.check_out) and att.shift_name != '休息' - and (not att.workflow_id or att.workflow_id.workflow_id.name != '请假') and not att.is_abnormal ] + leave_hours = 0 + leave_days = 0 + processed_leave_codes = set() # 记录已处理的请假单code,避免重复扣减 + + for att in attendances: + if att.workflow_id and att.workflow_id.workflow_id.name == '请假': + leave_record = self.env[att.workflow_id.res_model].sudo().browse(att.workflow_id.res_id) + if leave_record.code and leave_record.code in processed_leave_codes: + continue + + if leave_record.days: + leave_days += leave_record.days + if leave_record.code: + processed_leave_codes.add(leave_record.code) + + total_leave_days = leave_days + leave_total_days += leave_days if valid_attendances: - actual_attendance += 1 + daily_actual = max(1 - total_leave_days, 0) + actual_attendance += daily_actual + + rec.actual_attendance = max(actual_attendance, 0) for att in attendances: if att.is_late_card: