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):
|
def _check_validity(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.holiday_status_id.limit_leave_requests:
|
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.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.employee_id.sudo().emp_type and rec.employee_id.sudo().emp_type.id in rec.holiday_status_id.limit_emp_type.ids:
|
||||||
time_frame = {
|
time_frame = {
|
||||||
'week': timedelta(weeks=1),
|
'week': timedelta(weeks=1),
|
||||||
'month': timedelta(days=30),
|
'month': timedelta(days=30),
|
||||||
|
|
@ -316,7 +316,7 @@ class HRLeave(models.Model):
|
||||||
restriction_start_date = datetime.now() - time_frame
|
restriction_start_date = datetime.now() - time_frame
|
||||||
|
|
||||||
# Count the leave requests made by the employee within the restriction period
|
# 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),
|
('employee_id', '=', rec.employee_id.id),
|
||||||
('state', 'not in', ['cancel', 'refuse', 'draft']), # Adjust states if needed
|
('state', 'not in', ['cancel', 'refuse', 'draft']), # Adjust states if needed
|
||||||
('holiday_status_id', '=', rec.holiday_status_id.id),
|
('holiday_status_id', '=', rec.holiday_status_id.id),
|
||||||
|
|
@ -324,15 +324,18 @@ class HRLeave(models.Model):
|
||||||
('id','!=',rec.id)
|
('id','!=',rec.id)
|
||||||
])
|
])
|
||||||
if leave_count >= rec.holiday_status_id.limit_request_count:
|
if leave_count >= rec.holiday_status_id.limit_request_count:
|
||||||
raise ValidationError(_(
|
if rec.holiday_status_id.limit_request_count == 0:
|
||||||
"You have exceeded the maximum allowed leave requests (%s) for the selected period (%s)."
|
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)))
|
||||||
) % (rec.holiday_status_id.limit_request_count, rec.holiday_status_id.limit_request_type))
|
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))
|
||||||
|
|
||||||
return super(HRLeave, self)._check_validity()
|
return super(HRLeave, self)._check_validity()
|
||||||
|
|
||||||
def action_draft(self):
|
def action_draft(self):
|
||||||
for rec in 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"))
|
raise ValidationError(_("Only employee can submit his own leave"))
|
||||||
rec.submitted_date = fields.Datetime.now()
|
rec.submitted_date = fields.Datetime.now()
|
||||||
self._check_validity()
|
self._check_validity()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue