From 8dc455219fb00dd848fcb50ab3752f3006064d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Wed, 15 Apr 2026 11:25:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=96=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_hr_attendance/models/go_approval.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/yuthon_hr_attendance/models/go_approval.py b/yuthon_hr_attendance/models/go_approval.py index 4ca4cdf70..e11378be0 100644 --- a/yuthon_hr_attendance/models/go_approval.py +++ b/yuthon_hr_attendance/models/go_approval.py @@ -52,6 +52,25 @@ class GoApprovals(models.Model): if rec.is_day and (not rec.start_day_selection or not rec.end_day_selection): raise UserError("勾选按天后,必须选择开始时段和结束时段!") + @api.constrains('start_date', 'end_date', 'employee_ids') + def _check_date_overlap(self): + for rec in self: + if not rec.start_date or not rec.end_date or not rec.employee_ids: + continue + for employee in rec.employee_ids: + # 查找同一员工其他外出申请中时间段有交叉的记录(排除自身,排除已撤销的) + overlapping = self.env['go.approval'].search([ + ('id', '!=', rec.id), + ('employee_ids', 'in', employee.id), + ('start_date', '<=', rec.end_date), + ('end_date', '>=', rec.start_date), + ('reclaim_state', '=', False), + ]) + if overlapping: + raise ValidationError( + f"员工【{employee.name}】在 {rec.start_date} 至 {rec.end_date} 期间已有外出申请,相同时间段内不能重复创建。" + ) + def _get_default_name_title(self): return self._description if self._description else self._name From b6f73fb185c4101b102f1189d4808bba2fd2f3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Wed, 15 Apr 2026 11:31:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=96=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_hr_attendance/models/go_approval.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yuthon_hr_attendance/models/go_approval.py b/yuthon_hr_attendance/models/go_approval.py index e11378be0..59ec723c1 100644 --- a/yuthon_hr_attendance/models/go_approval.py +++ b/yuthon_hr_attendance/models/go_approval.py @@ -58,13 +58,12 @@ class GoApprovals(models.Model): if not rec.start_date or not rec.end_date or not rec.employee_ids: continue for employee in rec.employee_ids: - # 查找同一员工其他外出申请中时间段有交叉的记录(排除自身,排除已撤销的) + # 查找同一员工其他外出申请中时间段有交叉的记录(排除自身,active=False即撤销的自动被排除) overlapping = self.env['go.approval'].search([ ('id', '!=', rec.id), ('employee_ids', 'in', employee.id), ('start_date', '<=', rec.end_date), ('end_date', '>=', rec.start_date), - ('reclaim_state', '=', False), ]) if overlapping: raise ValidationError(