From 1fae3ce60b85e0f2a00558b2e9f0212bced5701c Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 21 Jul 2026 17:23:09 +0000 Subject: [PATCH] Fix sync not updating arrival/departure dates on re-sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- backend/api/sync_bookings.py | 4 ++++ backend/services/forecasting/pickup_v2_model.py | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/api/sync_bookings.py b/backend/api/sync_bookings.py index 9ea42ff..fdbc72b 100644 --- a/backend/api/sync_bookings.py +++ b/backend/api/sync_bookings.py @@ -455,6 +455,10 @@ def run_bookings_data_sync( ON CONFLICT (newbook_id) DO UPDATE SET booking_reference = EXCLUDED.booking_reference, booking_placed = COALESCE(EXCLUDED.booking_placed, newbook_bookings_data.booking_placed), + arrival_date = EXCLUDED.arrival_date, + departure_date = EXCLUDED.departure_date, + nights = EXCLUDED.nights, + room_number = EXCLUDED.room_number, status = EXCLUDED.status, total_amount = EXCLUDED.total_amount, tariff_total = EXCLUDED.tariff_total, diff --git a/backend/services/forecasting/pickup_v2_model.py b/backend/services/forecasting/pickup_v2_model.py index f4ac2f8..143120a 100644 --- a/backend/services/forecasting/pickup_v2_model.py +++ b/backend/services/forecasting/pickup_v2_model.py @@ -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