From faa021bd72537a4c77035f4ee5381b53cbc062b6 Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Sun, 1 Mar 2026 23:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=E7=A1=AE=E8=AE=A4=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/yuthon_vacation_reports.py | 26 +++++++++---------- .../views/yuthon_vacation_reports_views.xml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/yuthon_hr_attendance/models/yuthon_vacation_reports.py b/yuthon_hr_attendance/models/yuthon_vacation_reports.py index 1dc8c2558..3bcfcabc6 100644 --- a/yuthon_hr_attendance/models/yuthon_vacation_reports.py +++ b/yuthon_hr_attendance/models/yuthon_vacation_reports.py @@ -114,20 +114,20 @@ class YuthonVacationReports(models.Model): @api.model def cleanup_march_2026(self): - records = self.search([('display_date', '=', '2026年3月')]) + reports_ids = self.env['yuthon.vacation.reports'].search([('display_date', '=', '2026年3月')]) + # 按员工分组 + employee_groups = {} + for report in reports_ids: + if report.employee_id.id not in employee_groups: + employee_groups[report.employee_id.id] = [] + employee_groups[report.employee_id.id].append(report.id) - to_delete = self.env['yuthon.vacation.reports'] - processed_employees = set() - - for record in records: - emp_id = record.employee_id.id - if emp_id in processed_employees: - to_delete |= record - else: - processed_employees.add(emp_id) - - to_delete.unlink() - return True + # 对每个员工,保留第一条,删除其他 + to_delete = [] + for employee_id, report_list in employee_groups.items(): + if len(report_list) > 1: + # 保留第一个,删除后面的 + to_delete.extend(report_list[1:]) @api.model def leave_line(self): diff --git a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml index 51a0fbb74..c5b92226c 100644 --- a/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml +++ b/yuthon_hr_attendance/views/yuthon_vacation_reports_views.xml @@ -48,7 +48,7 @@ js_class="custom_vacation_put_button" limit="10">