Show spool availability indicator per job on jobs list

- filamentdb.spool_counts(): builds (material, color_name) → roll count
  from cached stock report; counts rolls_in_stock + rolls_in_use (non-graveyard)
- Jobs list: coloured dot before material — green (2+), yellow (1), red (0)
- FILAMENTDB_URL added to .env

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Martin Hohenberg
2026-06-18 22:22:32 +02:00
parent bc1769625e
commit 392acef28e
3 changed files with 27 additions and 2 deletions

View File

@@ -50,6 +50,20 @@ def available_materials() -> list[str]:
return sorted(out)
def spool_counts() -> dict[tuple[str, str], int]:
"""Returns {(material, color_name): available_rolls} from cached stock.
'Available' = rolls_in_stock + rolls_in_use (anything not in the graveyard).
Multiple filament types with the same material+color are summed.
"""
result: dict[tuple[str, str], int] = {}
for r in get_stock():
key = (r.get("material") or "", r.get("color_name") or "")
count = (r.get("rolls_in_stock") or 0) + (r.get("rolls_in_use") or 0)
result[key] = result.get(key, 0) + count
return result
def available_colors(material: str | None = None) -> list[str]:
"""Unique color names in stock, optionally filtered by material."""
rows = get_stock()