diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index 8689a747ef9a..40631069c4f8 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -1508,17 +1508,22 @@ def child_count(self): """ return self.children.count() - def is_in_stock(self, check_status: bool = True): + def is_in_stock( + self, check_status: bool = True, check_quantity: bool = True + ) -> bool: """Return True if this StockItem is "in stock". Args: check_status: If True, check the status of the StockItem. Defaults to True. + check_quantity: If True, check the quantity of the StockItem. Defaults to True. """ if check_status and self.status not in StockStatusGroups.AVAILABLE_CODES: return False + if check_quantity and self.quantity <= 0: + return False + 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 diff --git a/src/backend/InvenTree/stock/serializers.py b/src/backend/InvenTree/stock/serializers.py index 55164bca3e9c..49cb20b27dd5 100644 --- a/src/backend/InvenTree/stock/serializers.py +++ b/src/backend/InvenTree/stock/serializers.py @@ -1571,7 +1571,9 @@ def validate_pk(self, pk): 'STOCK_ALLOW_OUT_OF_STOCK_TRANSFER', backup_value=False, cache=False ) - if not allow_out_of_stock_transfer and not pk.is_in_stock(check_status=False): + if not allow_out_of_stock_transfer and not pk.is_in_stock( + check_status=False, check_quantity=False + ): raise ValidationError(_('Stock item is not in stock')) return pk diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index c362501458f3..0f408e0289d3 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -661,7 +661,6 @@ export default function StockDetail() { const stockActions = useMemo(() => { const inStock = user.hasChangeRole(UserRoles.stock) && - stockitem.quantity > 0 && !stockitem.sales_order && !stockitem.belongs_to && !stockitem.customer && @@ -717,7 +716,7 @@ export default function StockDetail() { { name: t`Remove`, tooltip: t`Remove Stock`, - hidden: serialized || !inStock, + hidden: serialized || !inStock || stockitem.quantity <= 0, icon: , onClick: () => { stockitem.pk && removeStockItem.open();