Skip to content

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

Make stocks type only for dashboard

fowczrekdfc3e6a1d9b0
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 6272e7f5b9..80ca260e60 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -188,7 +188,7 @@ class ProductVariant(CountableDjangoObjectType):
required=True,
description="Quantity of a product available for sale.",
deprecation_reason=(
- "Use the quantity_available field instead. "
+ "Use the quantityAvailable field instead. "
"This field will be removed after 2020-07-31."
),
)
@@ -265,6 +265,7 @@ class ProductVariant(CountableDjangoObjectType):
model = models.ProductVariant
@staticmethod
+ @permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_stocks(root: models.ProductVariant, info, country_code=None):
if not country_code:
return root.stocks.annotate_available_quantity().all()
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 8c45bf992b..32b7a51514 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -3719,7 +3719,7 @@ type ProductVariant implements Node & ObjectWithMetadata {
meta: [MetaStore]! @deprecated(reason: "Use the `metadata` field. This field will be removed after 2020-07-31.")
quantity: Int! @deprecated(reason: "Use the stock field instead. This field will be removed after 2020-07-31.")
quantityAllocated: Int @deprecated(reason: "Use the stock field instead. This field will be removed after 2020-07-31.")
- stockQuantity: Int! @deprecated(reason: "Use the quantity_available field instead. This field will be removed after 2020-07-31.")
+ stockQuantity: Int! @deprecated(reason: "Use the quantityAvailable field instead. This field will be removed after 2020-07-31.")
priceOverride: Money
pricing: VariantPricingInfo
isAvailable: Boolean @deprecated(reason: "Use the stock field instead. This field will be removed after 2020-07-31.")
@@ -4566,7 +4566,6 @@ type Stock implements Node {
productVariant: ProductVariant!
quantity: Int!
id: ID!
- stockQuantity: Int!
quantityAllocated: Int!
}
diff --git a/saleor/graphql/warehouse/types.py b/saleor/graphql/warehouse/types.py
index ee20136199..fe9c34ca34 100644
--- a/saleor/graphql/warehouse/types.py
+++ b/saleor/graphql/warehouse/types.py
@@ -1,5 +1,4 @@
import graphene
-from django.conf import settings
from django.db.models import Sum
from django.db.models.functions import Coalesce
@@ -61,10 +60,6 @@ class Warehouse(CountableDjangoObjectType):
class Stock(CountableDjangoObjectType):
- 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, "
@@ -80,14 +75,6 @@ class Stock(CountableDjangoObjectType):
interfaces = [graphene.relay.Node]
only_fields = ["warehouse", "product_variant", "quantity", "quantity_allocated"]
- @staticmethod
- def resolve_stock_quantity(root, *_args):
- quantity_allocated = root.allocations.aggregate(
- quantity_allocated=Coalesce(Sum("quantity_allocated"), 0)
- )["quantity_allocated"]
- available_quantity = max(root.quantity - quantity_allocated, 0)
- return min(available_quantity, settings.MAX_CHECKOUT_LINE_QUANTITY)
-
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_quantity(root, *_args):
diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.py
index f5823c9781..26a7c30be6 100644
--- a/saleor/warehouse/models.py
+++ b/saleor/warehouse/models.py
@@ -96,9 +96,6 @@ class Stock(models.Model):
unique_together = [["warehouse", "product_variant"]]
ordering = ("pk",)
- def __str__(self):
- return f"{self.product_variant} - {self.warehouse.name}"
-
def increase_stock(self, quantity: int, commit: bool = True):
"""Return given quantity of product to a stock."""
self.quantity = F("quantity") + quantity
diff --git a/tests/api/test_stock.py b/tests/api/test_stock.py
index cdb7d4fa14..5dfa3d5d4b 100644
--- a/tests/api/test_stock.py
+++ b/tests/api/test_stock.py
@@ -19,7 +19,6 @@ query stock($id: ID!) {
}
quantity
quantityAllocated
- stockQuantity
}
}
"""
@@ -165,27 +164,3 @@ def test_query_stocks_with_filters_product_variant__product(
total_count
== Stock.objects.filter(product_variant__product__name=product.name).count()
)
-
-
-def test_query_available_stock_quantity(
- staff_api_client, permission_manage_products, stock, settings
-):
- staff_api_client.user.user_permissions.add(permission_manage_products)
- stock_id = graphene.Node.to_global_id("Stock", stock.pk)
-
- available_quantity = stock.quantity - get_quantity_allocated_for_stock(stock)
- # set MAX_CHECKOUT_LINE_QUANTITY smaller than available quantity
- settings.MAX_CHECKOUT_LINE_QUANTITY = available_quantity - 1
-
- response = staff_api_client.post_graphql(QUERY_STOCK, variables={"id": stock_id})
- content = get_graphql_content(response)
- 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
- settings.MAX_CHECKOUT_LINE_QUANTITY = available_quantity + 1
-
- response = staff_api_client.post_graphql(QUERY_STOCK, variables={"id": stock_id})
- content = get_graphql_content(response)
- content_quantity_available = content["data"]["stock"]["stockQuantity"]
- assert content_quantity_available == available_quantity