Fix sites_list category field names — category_id/category_name, not site_category_*

The rates Newbook instance returns categories as category_id/category_name
on each site; also skip inactive categories.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-05 14:01:07 +00:00
parent 69c9b16a2b
commit 4977768645

View file

@ -97,8 +97,9 @@ class NewbookRatesClient:
"""
Fetch room categories by grouping the sites_list endpoint.
Each site includes site_category_id and site_category_name; categories
Each site carries its category as category_id/category_name; categories
are derived by grouping sites and counting rooms per category.
Inactive categories (category_active = "0") are skipped.
Returns:
List of dicts with {category_id, category_name, room_count}
@ -114,12 +115,14 @@ class NewbookRatesClient:
categories: Dict[str, Dict] = {}
for site in sites:
cat_id = str(site.get("site_category_id") or "")
cat_id = str(site.get("category_id") or site.get("site_category_id") or "")
if not cat_id:
continue
if str(site.get("category_active", "1")) == "0":
continue
entry = categories.setdefault(cat_id, {
"category_id": cat_id,
"category_name": site.get("site_category_name") or f"Category {cat_id}",
"category_name": site.get("category_name") or site.get("site_category_name") or f"Category {cat_id}",
"room_count": 0,
})
entry["room_count"] += 1