fix: dynamic VALID_CATEGORIES from DB categories table

Same issue as canteen-asset-tracker — hardcoded category set was
{Furniture, Appliances, Utensils, Equipment, Other}, missing all
vending-machine categories (Bev, Snack, GF Bev, GF Food, etc.).

- admin_server.py: _load_categories() from DB at startup
- cantaloupe_sync.py: reads from categories table instead of
  hardcoded set (was silently downgrading GF Bev→Other on sync!)
This commit is contained in:
Leo
2026-05-22 19:46:36 -04:00
parent a1dfe3665a
commit ae20c0507f
2 changed files with 21 additions and 6 deletions
+7 -3
View File
@@ -721,10 +721,14 @@ def approve_batch(batch_id: int, request: Request):
category = str(item.get("category", "Other")).strip()
status = str(item.get("status", "active")).strip()
# Validate enums
VALID_CATEGORIES = {"Furniture", "Appliances", "Utensils & Serveware", "Equipment", "Other"}
# Validate enums against DB categories table
VALID_STATUSES = {"active", "maintenance", "retired"}
if category not in VALID_CATEGORIES:
try:
valid_cats = {r[0] for r in conn.execute(
"SELECT name FROM categories").fetchall()}
except Exception:
valid_cats = {"Other"}
if category not in valid_cats:
category = "Other"
if status not in VALID_STATUSES:
status = "active"