Skip to content

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

Drop deprecated quantity fields (#6436)

Marcin Gębala9805909f9fcb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd21cfff32..cbed9da687 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add possibility to exclude products from shipping method - #6506 by @korycins
- Add availableShippingMethods to the Shop type - #6551 by @IKarbowiak
- Add delivery time to shipping method - #6564 by @IKarbowiak
+- Drop deprecated fields from the `ProductVariant` type: `quantity`, `quantityAllocated`, `stockQuantity`, `isAvailable` - #6436 by @maarcingebala
- Introduce file attributes - #6568 by @IKarbowiak
# 2.11.1
diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
index c62c07da13..15ef81cfbc 100644
--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
@@ -60,7 +60,6 @@ FRAGMENT_CHECKOUT_LINE = (
...Price
}
variant {
- stockQuantity
...ProductVariant
}
quantity
diff --git a/saleor/graphql/checkout/tests/benchmark/test_homepage.py b/saleor/graphql/checkout/tests/benchmark/test_homepage.py
index 9575750c11..bac90cf9bb 100644
--- a/saleor/graphql/checkout/tests/benchmark/test_homepage.py
+++ b/saleor/graphql/checkout/tests/benchmark/test_homepage.py
@@ -50,7 +50,6 @@ def test_user_checkout_details(user_api_client, customer_checkout, count_queries
...Price
}
variant {
- stockQuantity
...ProductVariant
}
quantity
diff --git a/saleor/graphql/product/tests/benchmark/test_product.py b/saleor/graphql/product/tests/benchmark/test_product.py
index ca36f85fd7..5ca16645ed 100644
--- a/saleor/graphql/product/tests/benchmark/test_product.py
+++ b/saleor/graphql/product/tests/benchmark/test_product.py
@@ -24,8 +24,6 @@ def test_product_details(product_with_image, api_client, count_queries, channel_
id
sku
name
- stockQuantity
- isAvailable
pricing {
discountLocalCurrency {
currency
diff --git a/saleor/graphql/product/tests/benchmark/test_variant.py b/saleor/graphql/product/tests/benchmark/test_variant.py
index d9167f9491..0b4357273d 100644
--- a/saleor/graphql/product/tests/benchmark/test_variant.py
+++ b/saleor/graphql/product/tests/benchmark/test_variant.py
@@ -36,8 +36,6 @@ def test_retrieve_variant_list(
id
sku
name
- stockQuantity
- isAvailable
pricing {
discountLocalCurrency {
currency
@@ -86,7 +84,6 @@ def test_retrieve_variant_list(
edges {
node {
...ProductVariantFields
- stockQuantity
quantityAvailable
quantityAvailablePl: quantityAvailable(countryCode: PL)
quantityAvailableUS: quantityAvailable(countryCode: US)
diff --git a/saleor/graphql/product/tests/deprecated/test_variant_availability.py b/saleor/graphql/product/tests/deprecated/test_variant_availability.py
deleted file mode 100644
index 0001061cc7..0000000000
--- a/saleor/graphql/product/tests/deprecated/test_variant_availability.py
+++ /dev/null
@@ -1,88 +0,0 @@
-import warnings
-
-import graphene
-
-from .....channel.utils import DEPRECATION_WARNING_MESSAGE
-from ....tests.utils import get_graphql_content
-
-QUERY_DEPRECATED_VARIANT_AVAILABILITY = """
- query variantAvailability($id: ID!) {
- productVariant(id: $id) {
- isAvailable
- stockQuantity
- quantityAvailable
- }
- }
-"""
-
-
-def test_variant_availability_without_inventory_tracking(
- api_client, variant_without_inventory_tracking, settings
-):
- variant = variant_without_inventory_tracking
- variables = {"id": graphene.Node.to_global_id("ProductVariant", variant.pk)}
- with warnings.catch_warnings(record=True) as warns:
- response = api_client.post_graphql(
- QUERY_DEPRECATED_VARIANT_AVAILABILITY, variables
- )
- content = get_graphql_content(response)
- variant_data = content["data"]["productVariant"]
- assert variant_data["isAvailable"] is True
- assert variant_data["stockQuantity"] == settings.MAX_CHECKOUT_LINE_QUANTITY
- assert variant_data["quantityAvailable"] == settings.MAX_CHECKOUT_LINE_QUANTITY
- assert any(
- [str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
- )
-
-
-def test_variant_availability(api_client, variant_with_many_stocks, settings):
- variant = variant_with_many_stocks
- variables = {"id": graphene.Node.to_global_id("ProductVariant", variant.pk)}
- with warnings.catch_warnings(record=True) as warns:
- response = api_client.post_graphql(
- QUERY_DEPRECATED_VARIANT_AVAILABILITY, variables
- )
- content = get_graphql_content(response)
- variant_data = content["data"]["productVariant"]
- assert variant_data["isAvailable"] is True
- assert variant_data["stockQuantity"] == 7
- assert variant_data["quantityAvailable"] == 7
- assert any(
- [str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
- )
-
-
-def test_variant_availability_without_inventory_tracking_without_stocks(
- api_client, variant_without_inventory_tracking, settings
-):
- variant = variant_without_inventory_tracking
- variant.stocks.all().delete()
- variables = {"id": graphene.Node.to_global_id("ProductVariant", variant.pk)}
- with warnings.catch_warnings(record=True) as warns:
- response = api_client.post_graphql(
- QUERY_DEPRECATED_VARIANT_AVAILABILITY, variables
- )
- content = get_graphql_content(response)
- variant_data = content["data"]["productVariant"]
- assert variant_data["isAvailable"] is True
- assert variant_data["stockQuantity"] == settings.MAX_CHECKOUT_LINE_QUANTITY
- assert variant_data["quantityAvailable"] == settings.MAX_CHECKOUT_LINE_QUANTITY
- assert any(
- [str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
- )
-
-
-def test_variant_availability_without_stocks(api_client, variant, settings):
- variables = {"id": graphene.Node.to_global_id("ProductVariant", variant.pk)}
- with warnings.catch_warnings(record=True) as warns:
- response = api_client.post_graphql(
- QUERY_DEPRECATED_VARIANT_AVAILABILITY, variables
- )
- content = get_graphql_content(response)
- variant_data = content["data"]["productVariant"]
- assert variant_data["isAvailable"] is False
- assert variant_data["stockQuantity"] == 0
- assert variant_data["quantityAvailable"] == 0
- assert any(
- [str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
- )
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index 679d0f7e6e..6cf66b27ae 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -6021,8 +6021,10 @@ mutation createProduct(
$name: String!,
$sku: String,
$stocks: [StockInput!],
- $basePrice: PositiveDecimal!
- $trackInventory: Boolean)
+ $basePrice: PositiveDecimal!,
+ $trackInventory: Boolean,
+ $country: CountryCode
+ )
{
productCreate(
input: {
@@ -6042,8 +6044,7 @@ mutation createProduct(
id
sku
trackInventory
- quantity
- stockQuantity
+ quantityAvailable(countryCode: $country)
}
}
productErrors {
diff --git a/saleor/graphql/product/tests/test_variant_pricing.py b/saleor/graphql/product/tests/test_variant_pricing.py
index 0edf3ee880..f800f29729 100644
--- a/saleor/graphql/product/tests/test_variant_pricing.py
+++ b/saleor/graphql/product/tests/test_variant_pricing.py
@@ -13,24 +13,20 @@ query ($channel: String) {
edges {
node {
variants {
- isAvailable
pricing {
onSale
-
discount {
currency
net {
amount
}
}
-
priceUndiscounted {
currency
net {
amount
}
}
-
price {
currency
net {
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index b358d875d3..5bdd5a132b 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -21,11 +21,7 @@ from ....product.utils.availability import (
get_variant_availability,
)
from ....product.utils.variants import get_variant_selection_attributes
-from ....warehouse.availability import (
- get_available_quantity,
- get_quantity_allocated,
- is_product_in_stock,
-)
+from ....warehouse.availability import is_product_in_stock
from ...account.enums import CountryCodeEnum
from ...attribute.filters import AttributeFilterInput
from ...attribute.resolvers import resolve_attributes
@@ -150,28 +146,6 @@ class ProductPricingInfo(BasePricingInfo):
@key(fields="id")
class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
- quantity = graphene.Int(
- required=True,
- description="Quantity of a product available for sale.",
- deprecation_reason=(
- "Use the stock field instead. This field will be removed after 2020-07-31."
- ),
- )
- quantity_allocated = graphene.Int(
- required=False,
- description="Quantity allocated for orders.",
- deprecation_reason=(
- "Use the stock field instead. This field will be removed after 2020-07-31."
- ),
- )
- stock_quantity = graphene.Int(
- required=True,
- description="Quantity of a product available for sale.",
- deprecation_reason=(
- "Use the quantityAvailable field instead. "
- "This field will be removed after 2020-07-31."
- ),
- )
channel_listings = graphene.List(
graphene.NonNull(ProductVariantChannelListing),
description="List of price information in channels for the product.",
@@ -183,12 +157,6 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
"only meant for displaying."
),
)
- is_available = graphene.Boolean(
- description="Whether the variant is in stock and visible or not.",
- deprecation_reason=(
- "Use the stock field instead. This field will be removed after 2020-07-31."
- ),
- )
attributes = graphene.List(
graphene.NonNull(SelectedAttribute),
required=True,
@@ -279,15 +247,6 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
def resolve_digital_content(root: ChannelContext[models.ProductVariant], *_args):
return getattr(root.node, "digital_content", None)
- @staticmethod
- def resolve_stock_quantity(root: ChannelContext[models.ProductVariant], info):
- if not root.node.track_inventory:
- return settings.MAX_CHECKOUT_LINE_QUANTITY
-
- return AvailableQuantityByProductVariantIdAndCountryCodeLoader(
- info.context
- ).load((root.node.id, info.context.country))
-
@staticmethod
def resolve_attributes(
root: ChannelContext[models.ProductVariant],
@@ -400,25 +359,6 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
lambda product: ChannelContext(node=product, channel_slug=root.channel_slug)
)
- @staticmethod
- def resolve_is_available(root: ChannelContext[models.ProductVariant], info):
- if not root.node.track_inventory:
- return True
-
- def is_variant_in_stock(available_quantity):
- return available_quantity > 0
-
- return (
- AvailableQuantityByProductVariantIdAndCountryCodeLoader(info.context)
- .load((root.node.id, info.context.country))
- .then(is_variant_in_stock)
- )
-
- @staticmethod
- @permission_required(ProductPermissions.MANAGE_PRODUCTS)
- def resolve_quantity(root: ChannelContext[models.ProductVariant], info):
- return get_available_quantity(root.node, info.context.country)
-
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_quantity_ordered(root: ChannelContext[models.ProductVariant], *_args):
@@ -426,12 +366,6 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
# `resolve_report_product_sales` resolver.
return getattr(root.node, "quantity_ordered", None)
- @staticmethod
- @permission_required(ProductPermissions.MANAGE_PRODUCTS)
- def resolve_quantity_allocated(root: ChannelContext[models.ProductVariant], info):
- country = info.context.country
- return get_quantity_allocated(root.node, country)
-
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_revenue(root: ChannelContext[models.ProductVariant], info, period):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 0939b68bf5..547540fee6 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4202,12 +4202,8 @@ type ProductVariant implements Node & ObjectWithMetadata {
weight: Weight
privateMetadata: [MetadataItem]!
metadata: [MetadataItem]!
- 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 quantityAvailable field instead. This field will be removed after 2020-07-31.")
channelListings: [ProductVariantChannelListing!]
pricing: VariantPricingInfo
- isAvailable: Boolean @deprecated(reason: "Use the stock field instead. This field will be removed after 2020-07-31.")
attributes(variantSelection: VariantAttributeScope): [SelectedAttribute!]!
costPrice: Money
margin: Int
diff --git a/saleor/warehouse/availability.py b/saleor/warehouse/availability.py
index 56e66a335d..1a08d2ddc7 100644
--- a/saleor/warehouse/availability.py
+++ b/saleor/warehouse/availability.py
@@ -11,12 +11,6 @@ if TYPE_CHECKING:
from ..product.models import Product, ProductVariant
-def _get_quantity_allocated(stocks: StockQuerySet) -> int:
- return stocks.aggregate(
- quantity_allocated=Coalesce(Sum("allocations__quantity_allocated"), 0)
- )["quantity_allocated"]
-
-
def _get_available_quantity(stocks: StockQuerySet) -> int:
results = stocks.aggregate(
total_quantity=Coalesce(Sum("quantity", distinct=True), 0),
@@ -82,13 +76,6 @@ def get_available_quantity(variant: "ProductVariant", country_code: str) -> int:
return _get_available_quantity(stocks)
-def get_quantity_allocated(variant: "ProductVariant", country_code: str) -> int:
- stocks = Stock.objects.get_variant_stocks_for_country(country_code, variant)
- if not stocks:
- return 0
- return _get_quantity_allocated(stocks)
-
-
def is_product_in_stock(product: "Product", country_code: str) -> bool:
"""Check if there is any variant of given product available in given country."""
stocks = Stock.objects.get_product_stocks_for_country(
diff --git a/saleor/warehouse/tests/test_stock_availability.py b/saleor/warehouse/tests/test_stock_availability.py
index 2fc0a4a404..fd825c9dc9 100644
--- a/saleor/warehouse/tests/test_stock_availability.py
+++ b/saleor/warehouse/tests/test_stock_availability.py
@@ -1,11 +1,7 @@
import pytest
from ...core.exceptions import InsufficientStock
-from ..availability import (
- check_stock_quantity,
- get_available_quantity,
- get_quantity_allocated,
-)
+from ..availability import check_stock_quantity, get_available_quantity
from ..models import Allocation
COUNTRY_CODE = "US"
@@ -70,21 +66,3 @@ def test_get_available_quantity_without_stocks(variant_with_many_stocks):
variant_with_many_stocks.stocks.all().delete()
available_quantity = get_available_quantity(variant_with_many_stocks, COUNTRY_CODE)
assert available_quantity == 0
-
-
-def test_get_quantity_allocated(
- variant_with_many_stocks, order_line_with_allocation_in_many_stocks
-):
- quantity_allocated = get_quantity_allocated(variant_with_many_stocks, COUNTRY_CODE)
- assert quantity_allocated == 3
-
-
-def test_get_quantity_allocated_without_allocation(variant_with_many_stocks):
- quantity_allocated = get_quantity_allocated(variant_with_many_stocks, COUNTRY_CODE)
- assert quantity_allocated == 0
-
-
-def test_get_quantity_allocated_without_stock(variant_with_many_stocks):
- variant_with_many_stocks.stocks.all().delete()
- quantity_allocated = get_quantity_allocated(variant_with_many_stocks, COUNTRY_CODE)
- assert quantity_allocated == 0