Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change Stock type in schema

Mira Szewczyk52265a3aef5f
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 8953a8529c..64687f964c 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4149,7 +4149,7 @@ type Stock implements Node {
quantity: Int!
quantityAllocated: Int!
id: ID!
- available: Int
+ stockQuantity: Int!
}
enum StockAvailability {
diff --git a/saleor/graphql/warehouse/types.py b/saleor/graphql/warehouse/types.py
index 61416bb34b..7da1afe4b8 100644
--- a/saleor/graphql/warehouse/types.py
+++ b/saleor/graphql/warehouse/types.py
@@ -1,11 +1,9 @@
import graphene
-from ...core.permissions import StockPermissions
from ...warehouse import models
from ...warehouse.availability import get_available_quantity_for_customer
from ..account.enums import CountryCodeEnum
from ..core.connection import CountableDjangoObjectType
-from ..decorators import permission_required
class WarehouseAddressInput(graphene.InputObjectType):
@@ -66,7 +64,18 @@ class StockInput(graphene.InputObjectType):
class Stock(CountableDjangoObjectType):
- available = graphene.Int(description="Quantity of a product available for sale.")
+ stock_quantity = graphene.Int(
+ description="Quantity of a product available for sale.", required=True
+ )
+
+ quantity = graphene.Int(
+ required=True,
+ description="Quantity of a product in the warehouse's possession, "
+ "including the allocated stock that is waiting for shipment.",
+ )
+ quantity_allocated = graphene.Int(
+ required=True, description="Quantity allocated for orders"
+ )
class Meta:
description = "Represents stock."
@@ -75,6 +84,13 @@ class Stock(CountableDjangoObjectType):
only_fields = ["warehouse", "product_variant", "quantity", "quantity_allocated"]
@staticmethod
- @permission_required(StockPermissions.MANAGE_STOCKS)
- def resolve_available(root, *_args):
+ def resolve_stock_quantity(root, *_args):
return get_available_quantity_for_customer(root)
+
+ @staticmethod
+ def resolve_quantity(root, *_args):
+ return root.quantity
+
+ @staticmethod
+ def resolve_quantity_allocated(root, *_args):
+ return root.quantity_allocated
diff --git a/tests/api/test_stock.py b/tests/api/test_stock.py
index 4ad6c4ac5d..61ed536ded 100644
--- a/tests/api/test_stock.py
+++ b/tests/api/test_stock.py
@@ -76,7 +76,7 @@ query stock($id: ID!) {
}
quantity
quantityAllocated
- available
+ stockQuantity
}
}
"""
@@ -418,7 +418,7 @@ def test_query_available_stock_quantity(
response = staff_api_client.post_graphql(QUERY_STOCK, variables={"id": stock_id})
content = get_graphql_content(response)
- content_quantity_available = content["data"]["stock"]["available"]
+ content_quantity_available = content["data"]["stock"]["stockQuantity"]
assert content_quantity_available == settings.MAX_CHECKOUT_LINE_QUANTITY
# set MAX_CHECKOUT_LINE_QUANTITY larger than available quantity
@@ -426,5 +426,5 @@ def test_query_available_stock_quantity(
response = staff_api_client.post_graphql(QUERY_STOCK, variables={"id": stock_id})
content = get_graphql_content(response)
- content_quantity_available = content["data"]["stock"]["available"]
+ content_quantity_available = content["data"]["stock"]["stockQuantity"]
assert content_quantity_available == available_quantity