Fix sync not updating arrival/departure dates on re-sync

ON CONFLICT clause was missing arrival_date, departure_date, nights, and
room_number — so early checkouts (where NewBook updates booking_departure
to the actual checkout date) never propagated to the DB columns. Reverts
the COUNT(DISTINCT) workaround since the root cause is now fixed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-21 17:23:09 +00:00
parent 7ebc31756d
commit 1fae3ce60b
2 changed files with 5 additions and 4 deletions

View file

@ -304,12 +304,9 @@ async def get_current_otb_rooms_by_category(db, stay_date: date) -> Dict[str, in
return {}
# Query actual bookings for real-time OTB count
# COUNT DISTINCT room_number so that multiple bookings on the same room
# (e.g. early-checkout Departed + new Arrived) count as one occupied room.
# COALESCE to newbook_id ensures unassigned rooms (no room_number) still count.
result = await db.execute(
text("""
SELECT category_id, COUNT(DISTINCT COALESCE(room_number, newbook_id)) as room_count
SELECT category_id, COUNT(*) as room_count
FROM newbook_bookings_data
WHERE arrival_date <= :stay_date
AND departure_date > :stay_date