2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

Zero stock fix (#8766)

* Change backend validation

- Allow stock adjustments with zero quantity

* Frontend changes
This commit is contained in:
Oliver
2024-12-26 10:42:07 +11:00
committed by GitHub
parent c79fc281fd
commit ae7f4e33d5
3 changed files with 11 additions and 5 deletions

View File

@ -1504,17 +1504,22 @@ class StockItem(
"""
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

View File

@ -1571,7 +1571,9 @@ class StockAdjustmentItemSerializer(serializers.Serializer):
'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