Skip to content

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

Applied changes from reviews

Mikail KOCAKf9b26eebd6cd
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 61ff305667..fc2830e685 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -315,10 +315,8 @@ class ProductVariant(CountableDjangoObjectType, MetadataObjectType):
return getattr(root, "digital_content", None)
@staticmethod
- def resolve_stock_quantity(root: models.ProductVariant, info):
+ def resolve_stock_quantity(root: models.ProductVariant, _info):
exact_quantity_available = root.quantity_available
- if info.context.user.has_perm("product.manage_products"):
- return exact_quantity_available
return min(exact_quantity_available, settings.MAX_CHECKOUT_LINE_QUANTITY)
@staticmethod
diff --git a/tests/api/benchmark/test_product.py b/tests/api/benchmark/test_product.py
index bfff3ee047..57ff1d17c9 100644
--- a/tests/api/benchmark/test_product.py
+++ b/tests/api/benchmark/test_product.py
@@ -24,6 +24,7 @@ def test_product_details(product, api_client, count_queries):
id
sku
name
+ stockQuantity
isAvailable
price {
currency
diff --git a/tests/api/benchmark/test_variant.py b/tests/api/benchmark/test_variant.py
index c7fb8c93cd..6e2e6110da 100644
--- a/tests/api/benchmark/test_variant.py
+++ b/tests/api/benchmark/test_variant.py
@@ -24,6 +24,7 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
id
sku
name
+ stockQuantity
isAvailable
price {
currency
@@ -48,6 +49,7 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
edges {
node {
...ProductVariantFields
+ stockQuantity
product {
...BasicProductFields
}
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 2bdadbc9ef..d4b4b0e9c9 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -2391,16 +2391,15 @@ VARIANT_QUANTITY_AVAILABLE_IN_STOCK_QUERY = """
"""
-def test_variant_available_stock_quantity_is_not_capped_for_authorized_user(
+def test_variant_available_stock_quantity_is_capped_for_authorized_user(
staff_api_client, permission_manage_products, variant, settings
):
"""
The exact quantity available in stock should be accessible for a staff
user having the permission to manage products.
"""
- settings.MAX_CHECKOUT_LINE_QUANTITY = 50
actual_stock_available = 60
- expected_stock_available = actual_stock_available
+ expected_stock_available = settings.MAX_CHECKOUT_LINE_QUANTITY = 50
variant.quantity = actual_stock_available
variant.quantity_allocated = 0