From 37b38d0b512b8a372c8bf94ec56f79f2722971b5 Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 3 Jun 2024 17:00:08 +0530 Subject: [PATCH] [FIX] BASE: Only admin can make the past request for employees in shift and work type requests --- base/models.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/base/models.py b/base/models.py index 844c5f902..b28477b7c 100644 --- a/base/models.py +++ b/base/models.py @@ -11,6 +11,7 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext_lazy as _ +from base import thread_local_middleware from base.horilla_company_manager import HorillaCompanyManager from base.thread_local_middleware import _thread_locals from horilla.models import HorillaModel @@ -765,8 +766,10 @@ class WorkTypeRequest(HorillaModel): return False def clean(self): - if self.requested_date < django.utils.timezone.now().date(): - raise ValidationError(_("Date must be greater than or equal to today")) + request = getattr(thread_local_middleware._thread_locals, "request", None) + if not request.user.is_superuser: + if self.requested_date < django.utils.timezone.now().date(): + raise ValidationError(_("Date must be greater than or equal to today")) if self.requested_till and self.requested_till < self.requested_date: raise ValidationError( _("End date must be greater than or equal to start date") @@ -874,8 +877,11 @@ class ShiftRequest(HorillaModel): ] def clean(self): - if not self.pk and self.requested_date < django.utils.timezone.now().date(): - raise ValidationError(_("Date must be greater than or equal to today")) + + request = getattr(thread_local_middleware._thread_locals, "request", None) + if not request.user.is_superuser: + if not self.pk and self.requested_date < django.utils.timezone.now().date(): + raise ValidationError(_("Date must be greater than or equal to today")) if self.requested_till and self.requested_till < self.requested_date: raise ValidationError( _("End date must be greater than or equal to start date")