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

ASU-1721 reservation recover on same place #445

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
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
30 changes: 27 additions & 3 deletions application_form/api/sales/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
ApplicationTimeNotFinishedException,
)
from application_form.services.lottery.machine import distribute_apartments
from application_form.services.queue import _adjust_positions
from application_form.services.reservation import (
transfer_reservation_to_another_customer,
)
Expand Down Expand Up @@ -243,15 +244,38 @@ def set_state(self, request, pk=None):
queue_position = state_change_event_serializer.validated_data.get(
"queue_position", None
)
if queue_position is not None:
reservation.queue_position = queue_position
new_state = state_change_event_serializer.validated_data.get("state")

if (
queue_position is not None
and new_state != ApartmentReservationState.CANCELED
):
# conver queue_position from string to number
if isinstance(queue_position, str):
queue_position = int(queue_position.lstrip("0"))

# position correction in queue
_adjust_positions(
ApartmentReservation.objects.filter(
apartment_uuid=reservation.apartment_uuid
),
"queue_position",
queue_position,
by=1,
)

# set state and position
state_change_event = reservation.set_state(
**state_change_event_serializer.validated_data,
user=request.user,
)

if queue_position is not None:
if (
queue_position is not None
and new_state != ApartmentReservationState.CANCELED
):
# save new position to database
reservation.queue_position = queue_position
reservation.save(update_fields=["queue_position"])

return Response(
Expand Down
2 changes: 2 additions & 0 deletions application_form/models/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def set_state(
)

if queue_position is not None:
if isinstance(queue_position, str):
queue_position = int(queue_position.lstrip("0"))
self.queue_position = queue_position

state_change_event = ApartmentReservationStateChangeEvent.objects.create(
Expand Down
Loading