diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 91eca465f..1e67e1a88 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -169,9 +169,10 @@ class YuthonVacationReports(models.Model): is_work = 0 leave_days = 0 test_days = 0 - right_days = 0 + statutory_days = 0 is_abnormal = 0 - actual_attendance = 0 # 实到天数 = 应到天数 - 请假总天数 + right_days = 0 + actual_attendance = 0 # 实到天数 = 应到天数 - 请假总天数 - 异常天数 total_leave_days = 0 # 请假工作流总天数(含小时折算) if rec.employee_id and rec.vacation_date: @@ -180,7 +181,7 @@ class YuthonVacationReports(models.Model): days_in_month = calendar.monthrange(year, month)[1] month_start = date(year, month, 1) month_end = date(year, month, days_in_month) - leave_days = rec._create_leave_record(rec.employee_id, month_start, month_end) + leave_days, holiday_days = rec._create_leave_record(rec.employee_id, month_start, month_end) entry_date = rec.employee_id.entry_date if not entry_date or month_start > entry_date: start_day = 1 @@ -220,25 +221,32 @@ class YuthonVacationReports(models.Model): elif related_model.hours: total_leave_days += float(related_model.hours) / 8 - actual_attendance = round(max(0, leave_days - total_leave_days), 1) + actual_attendance = round(max(0, leave_days - total_leave_days - is_abnormal), 1) month_start = date(year, month, 1) month_end = date(year, month, calendar.monthrange(year, month)[1]) - leave_days = rec._create_leave_record(rec.employee_id, month_start, month_end) + start_date = max(rec.employee_id.contract_id.date_start, month_start) + if rec.employee_id.contract_id.date_end: + end_date = min(rec.employee_id.contract_id.date_end, month_end) + else: + end_date = month_end + leave_days, statutory_days = rec._create_leave_record(rec.employee_id, start_date, end_date) probation_contract = self.env['hr.contract'].search([ ('employee_id', '=', rec.employee_id.id), ('is_probation', '=', True), ('end_date', '>=', month_start), - ('end_date', '<=', month_end) ], limit=1) if probation_contract: - test_days = rec._create_leave_record(rec.employee_id, month_start, probation_contract.end_date) - right_days = max(0.0, leave_days - test_days) + end_date = min(probation_contract.end_date, month_end) + start_date = max(probation_contract.start_date, month_start) + work_days, statutory_days = rec._create_leave_record(rec.employee_id, start_date, end_date) + test_days = work_days + statutory_days + right_days = (leave_days + statutory_days) - (work_days + statutory_days) else: test_days = 0 right_days = 0 - rec.should_attendance = leave_days + rec.should_attendance = leave_days + statutory_days rec.test_days = test_days rec.right_days = right_days rec.is_late_card = is_late @@ -246,7 +254,7 @@ class YuthonVacationReports(models.Model): rec.is_no_card = is_no rec.is_work = is_work rec.is_abnormal = is_abnormal - rec.actual_attendance = actual_attendance + rec.actual_attendance = actual_attendance + statutory_days - is_abnormal rec.att_mount = actual_attendance @@ -324,36 +332,43 @@ class YuthonVacationReports(models.Model): calendar_leaves = self.env['resource.calendar.leaves'].search( [("calendar_id.name", "=", "行政考勤工作日")]) - holidays_list = [] - shift_days_list = [] + holidays_list = [] # 节假日列表 + statutory_list = [] # 法定节假日列表 + shift_days_list = [] # 调休日列表 # 提取节假日和调休日 for leave in calendar_leaves: if leave.holidays: holidays_list.extend(leave.holidays.split(',')) + statutory_list.extend(leave.holidays.split(',')) if leave.alternate_rest_day: holidays_list.extend(leave.alternate_rest_day.split(',')) if leave.shift_replacement_day: shift_days_list.extend(leave.shift_replacement_day.split(',')) + # 去除日期中的前导零(如"01月05日"→"1月5日") holidays_list = [self.remove_leading_zero(date) for date in holidays_list] shift_days_list = [self.remove_leading_zero(date) for date in shift_days_list] + statutory_list = [self.remove_leading_zero(date) for date in statutory_list] work_days = 0 # 工作日计数 + statutory_days = 0 # 法定节假日计数 current_date = actual_start_date while current_date <= end_date: current_date_str = current_date.strftime('%m月%d日') current_date_str = self.remove_leading_zero(current_date_str) is_weekend = current_date.weekday() in [5, 6] + is_statutory = current_date_str in statutory_list is_holiday = current_date_str in holidays_list is_shift_day = current_date_str in shift_days_list - - # 判断是否为工作日 if is_shift_day or (not is_weekend and not is_holiday): work_days += 1 + if is_statutory: + statutory_days += 1 current_date += timedelta(days=1) - return work_days + + return work_days, statutory_days def remove_leading_zero(self, date_str): month, day = date_str.split('月') diff --git a/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml b/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml index 10b6b8a33..2c046b67a 100644 --- a/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml +++ b/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml @@ -57,7 +57,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -79,11 +79,11 @@ context="{'tree_view_ref': 'yuthon_hr_attendance.view_yuthon_shift_context', 'search_view_ref': 'yuthon_hr_attendance.search_yuthon_shift_context', 'order': 'start_datetime desc', - 'search_default_group_by_month': True,}"/> + 'search_default_group_by_month': True,}" options="{'no_create': True, 'no_edit':True}"/> + 'search_default_group_by_month': True,}" options="{'no_create': True, 'no_edit':True}"/>