Free rooms doesn't cause errors but further data verification is necessary

This commit is contained in:
Jonas Linter
2025-12-04 16:14:40 +01:00
parent ea3d886b87
commit 16d12f5b62
2 changed files with 194 additions and 0 deletions

View File

@@ -229,6 +229,16 @@ class FreeRoomsAction(AlpineBitsAction):
HttpStatusCode.BAD_REQUEST,
)
# Special case: CompleteSet with single empty Inventory element to reset all availability
if (
update_type == "CompleteSet"
and len(inventories) == 1
and inventories[0].status_application_control is None
and inventories[0].inv_counts is None
):
# This is valid - it's a reset request
return
encountered_standard = False
has_categories = False # Tracks if we've seen category reports (no InvCode)
has_rooms = False # Tracks if we've seen individual room reports (with InvCode)
@@ -315,7 +325,10 @@ class FreeRoomsAction(AlpineBitsAction):
self._validate_request(request, update_type, enforce_closing_order=True)
# Only delete if validation passes
# Delete availability data for all FreeRooms-sourced inventory
await self._delete_existing_availability(session, hotel.hotel_id)
# Delete stale inventory items that are sourced from FreeRooms
await self._delete_existing_inventory(session, hotel.hotel_id)
# Process the validated request
await self._process_inventories(
@@ -343,11 +356,29 @@ class FreeRoomsAction(AlpineBitsAction):
session: AsyncSession,
hotel_id: str,
) -> None:
"""Delete all room availability data for a hotel (regardless of source)."""
subquery = select(HotelInventory.id).where(HotelInventory.hotel_id == hotel_id)
await session.execute(
delete(RoomAvailability).where(RoomAvailability.inventory_id.in_(subquery))
)
async def _delete_existing_inventory(
self,
session: AsyncSession,
hotel_id: str,
) -> None:
"""Delete inventory items sourced from FreeRooms.
This preserves inventory items from other sources (e.g., HotelInventory endpoint)
as they are not managed by FreeRooms and should persist across CompleteSet updates.
"""
await session.execute(
delete(HotelInventory).where(
HotelInventory.hotel_id == hotel_id,
HotelInventory.source == SOURCE_FREEROOMS,
)
)
async def _process_inventories(
self,
session: AsyncSession,