Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix None checkers for quantity available resolver (#8353)
Aleksander Spyra52c4ad24b6f2
diff --git a/saleor/graphql/product/tests/test_variant_availability.py b/saleor/graphql/product/tests/test_variant_availability.pyindex afce70c218..f40ffa3cc9 100644--- a/saleor/graphql/product/tests/test_variant_availability.py+++ b/saleor/graphql/product/tests/test_variant_availability.py@@ -285,3 +285,21 @@ def test_variant_quantity_available_preorder_without_threshold(variant_data = content["data"]["productVariant"]assert variant_data["deprecatedByCountry"] == settings.MAX_CHECKOUT_LINE_QUANTITYassert variant_data["byAddress"] == settings.MAX_CHECKOUT_LINE_QUANTITY+++@override_settings(MAX_CHECKOUT_LINE_QUANTITY=15)+def test_variant_quantity_available_preorder_without_channel(+ api_client,+ preorder_variant_global_threshold,+ channel_USD,+):+ variant = preorder_variant_global_threshold+ variant.channel_listings.all().delete()+ variables = {+ "id": graphene.Node.to_global_id("ProductVariant", variant.pk),+ "country": COUNTRY_CODE,+ "channel": channel_USD.slug,+ }+ response = api_client.post_graphql(QUERY_VARIANT_AVAILABILITY, variables)+ content = get_graphql_content(response)+ assert not content["data"]["productVariant"]diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex d47d270c6d..0abeb23065 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -339,7 +339,10 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):).load((variant.id, str(root.channel_slug)))def calculate_available_per_channel(channel_listing):- if channel_listing.preorder_quantity_threshold is not None:+ if (+ channel_listing+ and channel_listing.preorder_quantity_threshold is not None+ ):return min(channel_listing.preorder_quantity_threshold- channel_listing.preorder_quantity_allocated,@@ -351,6 +354,8 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):).load(variant.id)def calculate_available_global(variant_channel_listings):+ if not variant_channel_listings:+ return settings.MAX_CHECKOUT_LINE_QUANTITYglobal_sold_units = sum(channel_listing.preorder_quantity_allocatedfor channel_listing in variant_channel_listings