!10817 Merge branch 'dev' of <a href="https://gitee.com/jinan-pengyusen-data/gzth">https://gitee.com/jinan-pengyusen-data/gzth</a> into dev_wang
Merge pull request !10817 from 李鹏宇/dev_wang
This commit is contained in:
@@ -52,6 +52,24 @@ 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:
|
||||
# 查找同一员工其他外出申请中时间段有交叉的记录(排除自身,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),
|
||||
])
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user