fix(spool): Add remaining_weight filter for low stock detection
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
- Add remaining_weight_lt and remaining_weight_gt filter params to spool API - Filter uses computed formula: initial_weight - used_weight (falls back to filament.weight) - Update home page to use queryParams instead of Refine filters - Fixes low stock badge count on dashboard Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,8 @@ async def find( # noqa: C901, PLR0912
|
||||
lot_nr: Optional[str] = None,
|
||||
allow_archived: bool = False,
|
||||
needs_weighing: Optional[bool] = None,
|
||||
remaining_weight_lt: Optional[float] = None,
|
||||
remaining_weight_gt: Optional[float] = None,
|
||||
sort_by: Optional[dict[str, SortOrder]] = None,
|
||||
limit: Optional[int] = None,
|
||||
offset: int = 0,
|
||||
@@ -170,6 +172,13 @@ async def find( # noqa: C901, PLR0912
|
||||
),
|
||||
)
|
||||
|
||||
# Filter by remaining_weight (computed as initial_weight - used_weight, falling back to filament.weight)
|
||||
remaining_weight_expr = coalesce(models.Spool.initial_weight, models.Filament.weight) - models.Spool.used_weight
|
||||
if remaining_weight_lt is not None:
|
||||
stmt = stmt.where(remaining_weight_expr < remaining_weight_lt)
|
||||
if remaining_weight_gt is not None:
|
||||
stmt = stmt.where(remaining_weight_expr > remaining_weight_gt)
|
||||
|
||||
total_count = None
|
||||
|
||||
if limit is not None:
|
||||
|
||||
Reference in New Issue
Block a user