Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development 1.1 removing holidays #405

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading