Skip to content

Commit

Permalink
Refactor vacation request viewset to simplify queryset ordering and r…
Browse files Browse the repository at this point in the history
…emove commented-out code; adjust HTML styles for better layout consistency
  • Loading branch information
Heibert committed Dec 2, 2024
1 parent b87434b commit 4a69eea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 47 deletions.
1 change: 0 additions & 1 deletion INSIGHTSAPI/vacation/templates/vacation_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
}

.content p {
margin-bottom: 35px;
font-size: 20px;
}
</style>
Expand Down
1 change: 0 additions & 1 deletion INSIGHTSAPI/vacation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def setUp(self):

def test_vacation_create(self):
"""Test creating a vacation endpoint."""

self.vacation_request["hr_is_approved"] = True # This is just a check
self.vacation_request["sat_is_working"] = False
response = self.client.post(
Expand Down
52 changes: 7 additions & 45 deletions INSIGHTSAPI/vacation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@


class VacationRequestViewSet(viewsets.ModelViewSet):
queryset = (
VacationRequest.objects.all().select_related("user").order_by("-created_at")
)
queryset = VacationRequest.objects.all().select_related("user").order_by("-pk")
serializer_class = VacationRequestSerializer
permission_classes = [IsAuthenticated]

Expand Down Expand Up @@ -163,44 +161,6 @@ def create(self, request, *args, **kwargs):
)
return response

# def list(self, request, *args, **kwargs):
# if request.user.job_position.name == "GERENTE DE GESTION HUMANA":
# queryset = self.queryset.all()
# # Check if the user is in payroll
# elif request.user.has_perm("vacation.payroll_approval"):
# queryset = self.queryset.all()
# # Check if the user has employee management permissions
# elif request.user.job_position.rank >= 2:
# children = self.request.user.area.get_children()
# # Check if the user is a manager
# if children and request.user.area.manager == request.user:
# queryset = self.queryset.filter(
# # Check if the user is the owner
# (Q(user=request.user))
# # Check if the user is a manager of the area
# | (Q(user__area__manager=request.user))
# # Check if the user is a manager of a child area
# | (Q(user__area__in=children))
# | (
# Q(user__job_position__rank__lt=request.user.job_position.rank)
# & Q(user__area=request.user.area)
# )
# )
# else:
# queryset = self.queryset.filter(
# Q(user=request.user)
# | (Q(user__area__manager=request.user))
# | (
# Q(user__job_position__rank__lt=request.user.job_position.rank)
# & Q(user__area=request.user.area)
# )
# )
# # The user is a regular employee
# else:
# queryset = self.queryset.filter(Q(user=request.user))
# serializer = self.serializer_class(queryset, many=True)
# return Response(serializer.data)

def partial_update(self, request, *args, **kwargs):

if isinstance(request.user, AnonymousUser):
Expand Down Expand Up @@ -287,12 +247,12 @@ def partial_update(self, request, *args, **kwargs):
[str(hr_user.company_email)],
)
payroll_user = User.objects.filter(
user_permissions__codename="payroll_is_approved"
user_permissions__codename="payroll_approval"
).first()
if not payroll_user:
mail_admins(
"No hay usuarios con el permiso de payroll_is_approved",
"No hay usuarios con el permiso de payroll_is_approved",
"No hay usuarios con el permiso de payroll_approval",
"No hay usuarios con el permiso de payroll_approval",
)
return response
create_notification(
Expand Down Expand Up @@ -443,7 +403,9 @@ def generate_response(self, request, pk=None):
open(str(settings.STATIC_ROOT) + "/images/just_logo.png", "rb").read()
).decode("utf-8"),
"company_logo_vertical": base64.b64encode(
open(str(settings.STATIC_ROOT) + "/images/vertical_logo.png", "rb").read()
open(
str(settings.STATIC_ROOT) + "/images/vertical_logo.png", "rb"
).read()
).decode("utf-8"),
}
# Import the html template
Expand Down

0 comments on commit 4a69eea

Please sign in to comment.