diff --git a/yuthon_hr_attendance/models/overtime_approval.py b/yuthon_hr_attendance/models/overtime_approval.py index 179b35065..4c2611136 100644 --- a/yuthon_hr_attendance/models/overtime_approval.py +++ b/yuthon_hr_attendance/models/overtime_approval.py @@ -58,6 +58,23 @@ class OvertimeApprovals(models.Model): name_title = fields.Char(default=_get_default_name_title) self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])]) + @api.constrains('start_time') + def _check_start_time(self): + for rec in self: + workflow_records = self.env['soong.workflow.record'].search([ + ('workflow_id.name', '=', '加班'), + ('create_uid', '=', self.env.user.id), + ]) + if not workflow_records: + continue + for wf_rec in workflow_records: + target_model = self.env[wf_rec.res_model] + target_record = target_model.browse(wf_rec.res_id) + if not target_record.exists() or not target_record.start_time: + continue + if target_record.start_time.date() == rec.start_time.date(): + raise UserError('当天已有加班审批,请重新选择开始时间') + def open_record(self): if self.start_time and self.end_time and self.employee_ids: start_date = fields.Date.to_date(self.start_time)