Skip to content

Commit

Permalink
Merge pull request #405 from codescalers/development_1.1_removing_hol…
Browse files Browse the repository at this point in the history
…idays

Development 1.1 removing holidays
  • Loading branch information
maayarosama authored Apr 24, 2024
2 parents de961d7 + 954d28f commit 0c29bca
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/cshr/views/vacations.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def post(self, request: Request) -> Response:
if serializer.is_valid():
balance = OfficeVacationBalance.objects.filter(year=year, location=location)
public_holidays = request.data["public_holidays"]

for holiday in public_holidays:
PublicHoliday.objects.get_or_create(
location=location, holiday_date=holiday
Expand All @@ -134,6 +135,15 @@ def post(self, request: Request) -> Response:
location=location, holiday_date__in=public_holidays
).values_list("id", flat=True)

if len(public_holidays) < len(balance[0].public_holidays.all()):
deleted_holidays = []
for holiday in balance[0].public_holidays.all():
if holiday.id not in public_holidays:
deleted_holidays.append(holiday)

for day in deleted_holidays:
PublicHoliday.objects.get(id=day.id).delete()

if len(balance) > 0:
balance[0].annual_leaves = serializer.validated_data.get(
"annual_leaves"
Expand All @@ -159,6 +169,7 @@ def post(self, request: Request) -> Response:
)



class BaseVacationsApiView(ListAPIView, GenericAPIView):
"""Class Vacations_APIView to create a new vacation into database or get all"""

Expand Down

0 comments on commit 0c29bca

Please sign in to comment.