mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
BOM Table Improvements (#3310)
* Bug fix for "multi delete" form - Was requesting entire LIST endpoint before launching form - Could cause extremely long delays before window opened * Improve rendering of "no stock available" in BOM table * Adds footer row to BOM table - Display total number of parts - Display minimum "can build" amount * Added extra information to footer row * Annotate 'ordering' quantity to BOM list - Display this quantity in the BOM table * Bump API version * JS linting * Allow BOM list to be filtered by "on_order" parameter * Add information showing amount that can be built once orders are received
This commit is contained in:
@ -1545,6 +1545,20 @@ class BomFilter(rest_filters.FilterSet):
|
||||
|
||||
return queryset
|
||||
|
||||
on_order = rest_filters.BooleanFilter(label="On order", method="filter_on_order")
|
||||
|
||||
def filter_on_order(self, queryset, name, value):
|
||||
"""Filter the queryset based on whether each line item has any stock on order"""
|
||||
|
||||
value = str2bool(value)
|
||||
|
||||
if value:
|
||||
queryset = queryset.filter(on_order__gt=0)
|
||||
else:
|
||||
queryset = queryset.filter(on_order=0)
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
class BomList(ListCreateDestroyAPIView):
|
||||
"""API endpoint for accessing a list of BomItem objects.
|
||||
|
@ -524,6 +524,8 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
purchase_price_range = serializers.SerializerMethodField()
|
||||
|
||||
on_order = serializers.FloatField(read_only=True)
|
||||
|
||||
# Annotated fields for available stock
|
||||
available_stock = serializers.FloatField(read_only=True)
|
||||
available_substitute_stock = serializers.FloatField(read_only=True)
|
||||
@ -593,6 +595,11 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
ref = 'sub_part__'
|
||||
|
||||
# Annotate with the total "on order" amount for the sub-part
|
||||
queryset = queryset.annotate(
|
||||
on_order=part.filters.annotate_on_order_quantity(ref),
|
||||
)
|
||||
|
||||
# Calculate "total stock" for the referenced sub_part
|
||||
# Calculate the "build_order_allocations" for the sub_part
|
||||
# Note that these fields are only aliased, not annotated
|
||||
@ -719,6 +726,8 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
'available_substitute_stock',
|
||||
'available_variant_stock',
|
||||
|
||||
# Annotated field describing quantity on order
|
||||
'on_order',
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user