Fix available_rooms to use is_included flag from room category settings

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

View file

@ -53,14 +53,15 @@ 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 available rooms per day excluding overflow (category_id='5') and maintenance rooms
# Pre-fetch available rooms per day using is_included flag from room categories settings
occ_result = await db.execute(
text("""
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
SELECT o.date, SUM(COALESCE(o.available, 0) - COALESCE(o.maintenance, 0)) AS available_rooms
FROM newbook_occupancy_report_data o
JOIN newbook_room_categories c ON o.category_id = c.site_id
WHERE o.date >= :start_date AND o.date <= :end_date
AND c.is_included = true
GROUP BY o.date
"""),
{"start_date": start, "end_date": end}
)