我想为员工检测一个One2many字段的值,即在一段时间内员工没有重叠,就像假期,但是对于多员工,我尝试了此代码,但是不起作用:
先谢谢您
在python文件中:
class HrMission(models.Model):
_name = 'hr.employee.mission'
_description = 'Mission object'
_inherit = 'mail.thread'
line_mission = fields.One2many('line.employee.mission','line_mission', string='Employee', help="Employee sent on mission",
copy=True, auto_join=True)
class LineEmployee(models.Model):
_name = 'line.employee.mission'
_description = 'Lignes des employés pour les mission'
line_mission = fields.Many2one('hr.employee.mission', string='Line mission Reference', required=True, ondelete='cascade', index=True, copy=False)
employee_id = fields.Many2one('hr.employee', string='Employee', help="Employee sent on mission",
required=True)
我的检查日期功能:
@api.constrains('mission_start_date', 'mission_end_date')
def _check_date(self):
for mission in self:
employee = self.env['line.employee.mission'].search_count([('employee_id', '=', self.ids)])
domain = [
('mission_start_date', '<=', mission.mission_end_date),
('mission_end_date', '>=', mission.mission_start_date),
('id', '!=', mission.id),
]
nmissions = self.search_count(domain)
if nmissions and employee:
raise exceptions.ValidationError('Vous ne pouvez pas avoir 2 missions qui se chevauchent le même jour!')