Time off submission issue
This commit is contained in:
parent
932607c079
commit
60c871c676
|
|
@ -305,8 +305,8 @@ class HRLeave(models.Model):
|
|||
def _check_validity(self):
|
||||
for rec in self:
|
||||
if rec.holiday_status_id.limit_leave_requests:
|
||||
if rec.holiday_status_id.limit_request_count and rec.holiday_status_id.limit_request_type and rec.holiday_status_id.limit_emp_type and rec.holiday_status_id.limit_request_count >= 0:
|
||||
if rec.employee_id.id in rec.holiday_status_id.limit_emp_type.ids:
|
||||
if rec.holiday_status_id.limit_request_type and rec.holiday_status_id.limit_emp_type and rec.holiday_status_id.limit_request_count >= 0:
|
||||
if rec.employee_id.sudo().emp_type and rec.employee_id.sudo().emp_type.id in rec.holiday_status_id.limit_emp_type.ids:
|
||||
time_frame = {
|
||||
'week': timedelta(weeks=1),
|
||||
'month': timedelta(days=30),
|
||||
|
|
@ -316,7 +316,7 @@ class HRLeave(models.Model):
|
|||
restriction_start_date = datetime.now() - time_frame
|
||||
|
||||
# Count the leave requests made by the employee within the restriction period
|
||||
leave_count = self.env['hr.leave'].search_count([
|
||||
leave_count = self.env['hr.leave'].sudo().search_count([
|
||||
('employee_id', '=', rec.employee_id.id),
|
||||
('state', 'not in', ['cancel', 'refuse', 'draft']), # Adjust states if needed
|
||||
('holiday_status_id', '=', rec.holiday_status_id.id),
|
||||
|
|
@ -324,6 +324,9 @@ class HRLeave(models.Model):
|
|||
('id','!=',rec.id)
|
||||
])
|
||||
if leave_count >= rec.holiday_status_id.limit_request_count:
|
||||
if rec.holiday_status_id.limit_request_count == 0:
|
||||
raise ValidationError(_("This time off type is not applicable for %s employee. Please contact your admin if required"%(rec.employee_id.sudo().emp_type.name)))
|
||||
else:
|
||||
raise ValidationError(_(
|
||||
"You have exceeded the maximum allowed leave requests (%s) for the selected period (%s)."
|
||||
) % (rec.holiday_status_id.limit_request_count, rec.holiday_status_id.limit_request_type))
|
||||
|
|
@ -332,7 +335,7 @@ class HRLeave(models.Model):
|
|||
|
||||
def action_draft(self):
|
||||
for rec in self:
|
||||
if rec.employee_id.user_id.id != self.env.user.id:
|
||||
if rec.sudo().employee_id.user_id.id != self.env.user.id:
|
||||
raise ValidationError(_("Only employee can submit his own leave"))
|
||||
rec.submitted_date = fields.Datetime.now()
|
||||
self._check_validity()
|
||||
|
|
|
|||
Loading…
Reference in New Issue