From 2912745300d81ec5bca696d9c0c6d02b452d45f2 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 21 Jul 2026 17:15:03 +0000 Subject: [PATCH] Fix current OTB overcounting Departed and Unconfirmed bookings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guests who check out early keep their original departure_date in NewBook, so Departed status with departure_date > stay_date were being counted as live OTB — inflating room count above physical capacity. Unconfirmed bookings are also provisional so excluded from live OTB. Prior-year queries retain all statuses since historical bookings will legitimately be in Departed state. Co-Authored-By: Claude Sonnet 4.6 --- backend/services/forecasting/pickup_v2_model.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/services/forecasting/pickup_v2_model.py b/backend/services/forecasting/pickup_v2_model.py index 143120a..36ab3b3 100644 --- a/backend/services/forecasting/pickup_v2_model.py +++ b/backend/services/forecasting/pickup_v2_model.py @@ -91,13 +91,15 @@ async def get_current_otb_revenue(db, stay_date: date) -> Decimal: return Decimal('0') # Query actual bookings for real-time OTB revenue + # Exclude 'Departed' — guests who checked out early retain their original departure_date + # so would be double-counted; exclude 'Unconfirmed' for same reason on live OTB result = await db.execute( text(""" SELECT raw_json FROM newbook_bookings_data WHERE arrival_date <= :stay_date AND departure_date > :stay_date - AND status IN ('Unconfirmed', 'Confirmed', 'Arrived', 'Departed') + AND status IN ('Confirmed', 'Arrived') AND category_id = ANY(:categories) """), { @@ -304,13 +306,14 @@ async def get_current_otb_rooms_by_category(db, stay_date: date) -> Dict[str, in return {} # Query actual bookings for real-time OTB count + # Exclude 'Departed' — early checkouts keep their original departure_date so would inflate count result = await db.execute( text(""" SELECT category_id, COUNT(*) as room_count FROM newbook_bookings_data WHERE arrival_date <= :stay_date AND departure_date > :stay_date - AND status IN ('Unconfirmed', 'Confirmed', 'Arrived', 'Departed') + AND status IN ('Confirmed', 'Arrived') AND category_id = ANY(:categories) GROUP BY category_id """),