diff --git a/src/backend/InvenTree/stock/filters.py b/src/backend/InvenTree/stock/filters.py index ac3098a632..1e6900f36f 100644 --- a/src/backend/InvenTree/stock/filters.py +++ b/src/backend/InvenTree/stock/filters.py @@ -37,28 +37,6 @@ def annotate_location_items(filter: Q = None): ) -def annotate_child_items(): - """Construct a queryset annotation which returns the number of children below a certain StockItem node in a StockItem tree.""" - child_stock_query = stock.models.StockItem.objects.filter( - tree_id=OuterRef('tree_id'), - lft__gt=OuterRef('lft'), - rght__lt=OuterRef('rght'), - level__gte=OuterRef('level'), - ) - - return Coalesce( - Subquery( - child_stock_query.annotate( - count=Func(F('pk'), function='COUNT', output_field=IntegerField()) - ) - .values('count') - .order_by() - ), - 0, - output_field=IntegerField(), - ) - - def annotate_sub_locations(): """Construct a queryset annotation which returns the number of sub-locations below a certain StockLocation node in a StockLocation tree.""" subquery = stock.models.StockLocation.objects.filter( diff --git a/src/backend/InvenTree/stock/serializers.py b/src/backend/InvenTree/stock/serializers.py index 89eaf4bf4a..a59895ebbf 100644 --- a/src/backend/InvenTree/stock/serializers.py +++ b/src/backend/InvenTree/stock/serializers.py @@ -604,7 +604,7 @@ class StockItemSerializer( queryset = queryset.annotate(installed_items=SubqueryCount('installed_parts')) # Annotate with the total number of "child items" (split stock items) - queryset = queryset.annotate(child_items=stock.filters.annotate_child_items()) + queryset = queryset.annotate(child_items=SubqueryCount('children')) return queryset