mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Part table stock filtering (#4462)
* Update PartSerializer queryset annotation - Add 'total_stock' (in_stock + variant_stock) - Update 'unallocated_stock' to use total_stock * Allow API filtering by total_in_stock value * Refactor partStockLabel method - We'll use this in the partTable also - Allow us to prevent further API calls * Cleanup loadPartTable * Refactor part variant table * More updates to part badge function * Bump API version * js linting
This commit is contained in:
@ -423,7 +423,6 @@ class PartSerializer(RemoteImageMixin, InvenTreeModelSerializer):
|
||||
'full_name',
|
||||
'image',
|
||||
'in_stock',
|
||||
'variant_stock',
|
||||
'ordering',
|
||||
'building',
|
||||
'IPN',
|
||||
@ -444,10 +443,12 @@ class PartSerializer(RemoteImageMixin, InvenTreeModelSerializer):
|
||||
'stock_item_count',
|
||||
'suppliers',
|
||||
'thumbnail',
|
||||
'total_in_stock',
|
||||
'trackable',
|
||||
'unallocated_stock',
|
||||
'units',
|
||||
'variant_of',
|
||||
'variant_stock',
|
||||
'virtual',
|
||||
'pricing_min',
|
||||
'pricing_max',
|
||||
@ -554,11 +555,20 @@ class PartSerializer(RemoteImageMixin, InvenTreeModelSerializer):
|
||||
allocated_to_build_orders=part.filters.annotate_build_order_allocations(),
|
||||
)
|
||||
|
||||
# Annotate the queryset with the 'total_in_stock' quantity
|
||||
# This is the 'in_stock' quantity summed with the 'variant_stock' quantity
|
||||
queryset = queryset.annotate(
|
||||
total_in_stock=ExpressionWrapper(
|
||||
F('in_stock') + F('variant_stock'),
|
||||
output_field=models.DecimalField(),
|
||||
)
|
||||
)
|
||||
|
||||
# Annotate with the total 'available stock' quantity
|
||||
# This is the current stock, minus any allocations
|
||||
queryset = queryset.annotate(
|
||||
unallocated_stock=ExpressionWrapper(
|
||||
F('in_stock') - F('allocated_to_sales_orders') - F('allocated_to_build_orders'),
|
||||
F('total_in_stock') - F('allocated_to_sales_orders') - F('allocated_to_build_orders'),
|
||||
output_field=models.DecimalField(),
|
||||
)
|
||||
)
|
||||
@ -579,6 +589,7 @@ class PartSerializer(RemoteImageMixin, InvenTreeModelSerializer):
|
||||
building = serializers.FloatField(read_only=True)
|
||||
in_stock = serializers.FloatField(read_only=True)
|
||||
variant_stock = serializers.FloatField(read_only=True)
|
||||
total_in_stock = serializers.FloatField(read_only=True)
|
||||
ordering = serializers.FloatField(read_only=True)
|
||||
stock_item_count = serializers.IntegerField(read_only=True)
|
||||
suppliers = serializers.IntegerField(read_only=True)
|
||||
|
Reference in New Issue
Block a user