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:
+7
-3
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user