2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

[PUI] Stock Detail (#8274)

* Add "in_stock" attribute to StockItem API

* Add "unavailable" badge to StockDetail page

* Hide stock actions menu for "unavailable" stock

* Fix renderer for StockItemTable

* refactor stock table display

* Add 'date' type details field

* Disable "expiry" information on StockDetailPage

* Icon fix

* Bump API version
This commit is contained in:
Oliver
2024-10-11 23:39:07 +11:00
committed by GitHub
parent 48bb5fd579
commit f77c8a5b5b
7 changed files with 136 additions and 78 deletions

View File

@ -1,13 +1,16 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 267
INVENTREE_API_VERSION = 268
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
268 - 2024-10-11 : https://github.com/inventree/InvenTree/pull/8274
- Adds "in_stock" attribute to the StockItem serializer
267 - 2024-10-8 : https://github.com/inventree/InvenTree/pull/8250
- Remove "allocations" field from the SalesOrderShipment API endpoint(s)
- Add "allocated_items" field to the SalesOrderShipment API endpoint(s)

View File

@ -441,6 +441,7 @@ class StockItem(
tags = TaggableManager(blank=True)
# A Query filter which will be re-used in multiple places to determine if a StockItem is actually "in stock"
# See also: StockItem.in_stock() method
IN_STOCK_FILTER = Q(
quantity__gt=0,
sales_order=None,
@ -1404,16 +1405,20 @@ class StockItem(
return self.children.count()
@property
def in_stock(self):
def in_stock(self) -> bool:
"""Returns True if this item is in stock.
See also: IN_STOCK_FILTER
See also: StockItem.IN_STOCK_FILTER for the db optimized version of this check.
"""
query = StockItem.objects.filter(pk=self.pk)
query = query.filter(StockItem.IN_STOCK_FILTER)
return query.exists()
return all([
self.quantity > 0, # Quantity must be greater than zero
self.sales_order is None, # Not assigned to a SalesOrder
self.belongs_to is None, # Not installed inside another StockItem
self.customer is None, # Not assigned to a customer
self.consumed_by is None, # Not consumed by a build
not self.is_building, # Not part of an active build
self.status in StockStatusGroups.AVAILABLE_CODES, # Status is "available"
])
@property
def can_adjust_location(self):

View File

@ -358,6 +358,7 @@ class StockItemSerializer(
'customer',
'delete_on_deplete',
'expiry_date',
'in_stock',
'is_building',
'link',
'location',
@ -468,6 +469,8 @@ class StockItemSerializer(
child=serializers.DictField(), source='location.get_path', read_only=True
)
in_stock = serializers.BooleanField(read_only=True, label=_('In Stock'))
"""
Field used when creating a stock item
"""
@ -519,6 +522,10 @@ class StockItemSerializer(
'supplier_part__manufacturer_part__manufacturer',
'supplier_part__tags',
'test_results',
'customer',
'belongs_to',
'sales_order',
'consumed_by',
'tags',
)