mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 13:58:47 +00:00
Adds annotation for build order allocation count
This commit is contained in:
parent
4e100643f5
commit
94068f6bad
@ -386,6 +386,22 @@ class PartSerializer(InvenTreeModelSerializer):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Annotate with the number of stock items allocated to build orders.
|
||||||
|
This annotation is modeled on Part.build_order_allocations() method
|
||||||
|
"""
|
||||||
|
bo_allocation_filter = Q(
|
||||||
|
build__status__in=BuildStatus.ACTIVE_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
allocated_to_build_orders=Coalesce(
|
||||||
|
SubquerySum('stock_items__allocations__quantity', filter=bo_allocation_filter),
|
||||||
|
Decimal(0),
|
||||||
|
output_field=models.DecimalField(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def get_starred(self, part):
|
def get_starred(self, part):
|
||||||
@ -399,6 +415,7 @@ class PartSerializer(InvenTreeModelSerializer):
|
|||||||
category_detail = CategorySerializer(source='category', many=False, read_only=True)
|
category_detail = CategorySerializer(source='category', many=False, read_only=True)
|
||||||
|
|
||||||
# Calculated fields
|
# Calculated fields
|
||||||
|
allocated_to_build_orders = serializers.FloatField(read_only=True)
|
||||||
allocated_to_sales_orders = serializers.FloatField(read_only=True)
|
allocated_to_sales_orders = serializers.FloatField(read_only=True)
|
||||||
building = serializers.FloatField(read_only=True)
|
building = serializers.FloatField(read_only=True)
|
||||||
in_stock = serializers.FloatField(read_only=True)
|
in_stock = serializers.FloatField(read_only=True)
|
||||||
@ -423,6 +440,7 @@ class PartSerializer(InvenTreeModelSerializer):
|
|||||||
partial = True
|
partial = True
|
||||||
fields = [
|
fields = [
|
||||||
'active',
|
'active',
|
||||||
|
'allocated_to_build_orders',
|
||||||
'allocated_to_sales_orders',
|
'allocated_to_sales_orders',
|
||||||
'assembly',
|
'assembly',
|
||||||
'category',
|
'category',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user