mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Add field for substitute_stock (work in progress)
This commit is contained in:
parent
c6ba104ae8
commit
e4ca638a2e
@ -579,6 +579,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
# Annotated fields
|
# Annotated fields
|
||||||
available_stock = serializers.FloatField(read_only=True)
|
available_stock = serializers.FloatField(read_only=True)
|
||||||
|
substitute_stock = serializers.FloatField(read_only=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# part_detail and sub_part_detail serializers are only included if requested.
|
# part_detail and sub_part_detail serializers are only included if requested.
|
||||||
@ -637,9 +638,13 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
# Calculate "total stock" for the referenced sub_part
|
# Calculate "total stock" for the referenced sub_part
|
||||||
# Calculate the "build_order_allocations" for the sub_part
|
# Calculate the "build_order_allocations" for the sub_part
|
||||||
|
# Note that these fields are only aliased, not annotated
|
||||||
queryset = queryset.alias(
|
queryset = queryset.alias(
|
||||||
total_stock=Coalesce(
|
total_stock=Coalesce(
|
||||||
SubquerySum('sub_part__stock_items__quantity', filter=StockItem.IN_STOCK_FILTER),
|
SubquerySum(
|
||||||
|
'sub_part__stock_items__quantity',
|
||||||
|
filter=StockItem.IN_STOCK_FILTER
|
||||||
|
),
|
||||||
Decimal(0),
|
Decimal(0),
|
||||||
output_field=models.DecimalField(),
|
output_field=models.DecimalField(),
|
||||||
),
|
),
|
||||||
@ -674,6 +679,18 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Extract similar information for any 'substitute' parts
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
substitute_stock=Coalesce(
|
||||||
|
SubquerySum(
|
||||||
|
'substitutes__part__stock_items__quantity',
|
||||||
|
filter=StockItem.IN_STOCK_FILTER,
|
||||||
|
),
|
||||||
|
Decimal(0),
|
||||||
|
output_field=models.DecimalField(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def get_purchase_price_range(self, obj):
|
def get_purchase_price_range(self, obj):
|
||||||
@ -748,7 +765,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
# Annotated fields describing available quantity
|
# Annotated fields describing available quantity
|
||||||
'available_stock',
|
'available_stock',
|
||||||
|
'substitute_stock',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user