Fix available_rooms query: use newbook_occupancy_report_data not daily_occupancy

The table is newbook_occupancy_report_data (per-category rows). Aggregate
SUM(available - maintenance) WHERE category_id != '5' to get the correct
available room count excluding overflow and maintenance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 11:32:35 +00:00
parent e04ae18711
commit 4e783bd508

View file

@ -53,12 +53,14 @@ async def get_rooms_forecast(
row = result.fetchone()
fallback_total_rooms = int(row.config_value) if row and row.config_value else 30
# Pre-fetch daily_occupancy available_rooms for the whole range (excludes overflow/maintenance)
# Pre-fetch available rooms per day excluding overflow (category_id='5') and maintenance rooms
occ_result = await db.execute(
text("""
SELECT date, available_rooms
FROM daily_occupancy
SELECT date, SUM(available - COALESCE(maintenance, 0)) AS available_rooms
FROM newbook_occupancy_report_data
WHERE date >= :start_date AND date <= :end_date
AND category_id != '5'
GROUP BY date
"""),
{"start_date": start, "end_date": end}
)