2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Zero stock fix (#8766) (#8768)

* Change backend validation

- Allow stock adjustments with zero quantity

* Frontend changes

(cherry picked from commit ae7f4e33d52f671584e9e99fc2b486f55f831edc)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-12-26 11:26:04 +11:00 committed by GitHub
parent 40245a6c4a
commit cab7a06146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -1508,17 +1508,22 @@ class StockItem(
""" """
return self.children.count() 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". """Return True if this StockItem is "in stock".
Args: Args:
check_status: If True, check the status of the StockItem. Defaults to True. 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: if check_status and self.status not in StockStatusGroups.AVAILABLE_CODES:
return False return False
if check_quantity and self.quantity <= 0:
return False
return all([ return all([
self.quantity > 0, # Quantity must be greater than zero
self.sales_order is None, # Not assigned to a SalesOrder self.sales_order is None, # Not assigned to a SalesOrder
self.belongs_to is None, # Not installed inside another StockItem self.belongs_to is None, # Not installed inside another StockItem
self.customer is None, # Not assigned to a customer 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 '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')) raise ValidationError(_('Stock item is not in stock'))
return pk return pk

View File

@ -661,7 +661,6 @@ export default function StockDetail() {
const stockActions = useMemo(() => { const stockActions = useMemo(() => {
const inStock = const inStock =
user.hasChangeRole(UserRoles.stock) && user.hasChangeRole(UserRoles.stock) &&
stockitem.quantity > 0 &&
!stockitem.sales_order && !stockitem.sales_order &&
!stockitem.belongs_to && !stockitem.belongs_to &&
!stockitem.customer && !stockitem.customer &&
@ -717,7 +716,7 @@ export default function StockDetail() {
{ {
name: t`Remove`, name: t`Remove`,
tooltip: t`Remove Stock`, tooltip: t`Remove Stock`,
hidden: serialized || !inStock, hidden: serialized || !inStock || stockitem.quantity <= 0,
icon: <InvenTreeIcon icon='remove' iconProps={{ color: 'red' }} />, icon: <InvenTreeIcon icon='remove' iconProps={{ color: 'red' }} />,
onClick: () => { onClick: () => {
stockitem.pk && removeStockItem.open(); stockitem.pk && removeStockItem.open();