Coverage for src/backend/InvenTree/build/filters.py: 67%
6 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Queryset filtering helper functions for the Build app."""
3from django.db.models import DecimalField, ExpressionWrapper, F, Max, Sum
4from django.db.models.functions import Coalesce, Greatest
7def annotate_required_quantity():
8 """Annotate the 'required' quantity for each build item in the queryset."""
9 # Note: The use of Max() here is intentional, to avoid aggregation issues in MySQL
10 # Ref: https://github.com/inventree/InvenTree/pull/10398
11 return Greatest(
12 ExpressionWrapper(
13 Max(F('quantity')) - Max(F('consumed')), output_field=DecimalField()
14 ),
15 0,
16 output_field=DecimalField(),
17 )
20def annotate_allocated_quantity():
21 """Annotate the 'allocated' quantity for each build item in the queryset."""
22 return Coalesce(Sum('allocations__quantity'), 0, output_field=DecimalField())