Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Convert country code to Country instance (#6901)
Marcin Gębala51d8b65d1c01
diff --git a/saleor/graphql/product/tests/test_variant_pricing.py b/saleor/graphql/product/tests/test_variant_pricing.pyindex b9d29bb7d8..77d2f05319 100644--- a/saleor/graphql/product/tests/test_variant_pricing.py+++ b/saleor/graphql/product/tests/test_variant_pricing.py@@ -1,5 +1,6 @@from unittest.mock import Mock+from django_countries.fields import Countryfrom prices import Money, TaxedMoneyfrom ....plugins.manager import PluginsManager@@ -140,7 +141,7 @@ def test_variant_pricing(discounts=[],channel=channel_USD,local_currency="PLN",- country="US",+ country=Country("US"),)assert pricing.price_local_currency.currency == "PLN" # type: ignorediff --git a/saleor/graphql/product/types/channels.py b/saleor/graphql/product/types/channels.pyindex 34394e8307..bb605bbbb5 100644--- a/saleor/graphql/product/types/channels.py+++ b/saleor/graphql/product/types/channels.py@@ -1,8 +1,7 @@from dataclasses import asdictimport graphene--from saleor.graphql.product.dataloaders.products import ProductByIdLoader+from django_countries.fields import Countryfrom ....core.permissions import ProductPermissionsfrom ....core.utils import get_currency_for_country@@ -21,6 +20,7 @@ from ...discount.dataloaders import DiscountsByDateTimeLoaderfrom ...utils import get_user_country_contextfrom ..dataloaders import (CollectionsByProductIdLoader,+ ProductByIdLoader,ProductVariantsByProductIdLoader,VariantChannelListingByVariantIdAndChannelSlugLoader,VariantsChannelListingByProductIdAndChanneSlugLoader,@@ -178,7 +178,7 @@ class ProductChannelListing(CountableDjangoObjectType):collections=collections,discounts=discounts,channel=channel,- country=country_code,+ country=Country(country_code),local_currency=get_currency_for_country(country_code),diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex 4b8117ba96..efccc0894b 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -3,6 +3,7 @@ from typing import Optionalimport graphenefrom django.conf import settings+from django_countries.fields import Countryfrom graphene import relayfrom graphene_federation import keyfrom graphql.error import GraphQLError@@ -378,7 +379,7 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):collections=collections,discounts=discounts,channel=channel,- country=country_code,+ country=Country(country_code),local_currency=get_currency_for_country(country_code),@@ -656,7 +657,7 @@ class Product(ChannelContextTypeWithMetadata, CountableDjangoObjectType):collections=collections,discounts=discounts,channel=channel,- country=country_code,+ country=Country(country_code),local_currency=get_currency_for_country(country_code),diff --git a/saleor/product/tests/test_product_availability.py b/saleor/product/tests/test_product_availability.pyindex 760513586b..7767254c88 100644--- a/saleor/product/tests/test_product_availability.py+++ b/saleor/product/tests/test_product_availability.py@@ -2,6 +2,7 @@ import datetimefrom decimal import Decimalfrom unittest.mock import Mock+from django_countries.fields import Countryfrom freezegun import freeze_timefrom prices import Money, TaxedMoney, TaxedMoneyRange@@ -29,7 +30,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):channel=channel_USD,collections=[],discounts=[],- country="PL",+ country=Country("PL"),)taxed_price_range = TaxedMoneyRange(start=taxed_price, stop=taxed_price)assert availability.price_range == taxed_price_range@@ -50,7 +51,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):discounts=[],channel=channel_USD,local_currency="PLN",- country="PL",+ country=Country("PL"),)assert availability.price_range_local_currency.start.currency == "PLN"@@ -62,7 +63,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):collections=[],discounts=[],channel=channel_USD,- country="PL",+ country=Country("PL"),)assert availability.price_range.start.tax.amountassert availability.price_range.stop.tax.amount@@ -91,7 +92,7 @@ def test_availability_with_all_variant_channel_listings(stock, channel_USD):channel=channel_USD,collections=[],discounts=[],- country="PL",+ country=Country("PL"),)# then@@ -120,7 +121,7 @@ def test_availability_with_missing_variant_channel_listings(stock, channel_USD):channel=channel_USD,collections=[],discounts=[],- country="PL",+ country=Country("PL"),)# then@@ -147,7 +148,7 @@ def test_availability_without_variant_channel_listings(stock, channel_USD):channel=channel_USD,collections=[],discounts=[],- country="PL",+ country=Country("PL"),)# thendiff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.pyindex 97294cb896..00dfd629cd 100644--- a/saleor/product/utils/availability.py+++ b/saleor/product/utils/availability.py@@ -2,6 +2,7 @@ from dataclasses import dataclassfrom typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Unionimport opentracing+from django_countries.fields import Countryfrom prices import MoneyRange, TaxedMoney, TaxedMoneyRangefrom ...channel.models import Channel@@ -145,7 +146,7 @@ def get_product_availability(collections: Iterable[Collection],discounts: Iterable[DiscountInfo],channel: Channel,- country: Optional[str] = None,+ country: Optional[Country] = None,local_currency: Optional[str] = None,plugins: Optional["PluginsManager"] = None,) -> ProductAvailability:@@ -222,7 +223,7 @@ def get_variant_availability(collections: Iterable[Collection],discounts: Iterable[DiscountInfo],channel: Channel,- country: Optional[str] = None,+ country: Optional[Country] = None,local_currency: Optional[str] = None,plugins: Optional["PluginsManager"] = None,) -> VariantAvailability: