Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop integration with openexchangerates API (#13175)
Marcin Gębala25557dcbc162
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a9bd15eef2..2845d679df 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,7 +5,15 @@ All notable, unreleased changes to this project will be documented in this file.# 3.15.0 [Unreleased]### Breaking changes+- Remove `OrderBulkCreateInput.trackingClientId` field - #13146 by @SzymJ+- Drop backend integration with Open Exchange Rates API - #13175 by @maarcingebala+ - Note: this changes doesn't affect Saleor Cloud users, as the integration was never enabled there.+ - After this change, the following fields in API alway return `null` values:+ - `ProductPricingInfo.discountLocalCurrency`+ - `ProductPricingInfo.priceRangeLocalCurrency`+ - `VariantPricingInfo.discountLocalCurrency`+ - `VariantPricingInfo.priceLocalCurrency`### GraphQL API@@ -13,9 +21,11 @@ All notable, unreleased changes to this project will be documented in this file.- Deprecate `Order.trackingClientId` field - #13146 by @SzymJ### Saleor Apps+- Introduce `Saleor-Schema-Version` HTTP header in app manifest fetching and app installation handshake requests. - #13075 by @przlada### Other changes+- Expand metric units to support more types of products. - #13043 by @FremahA- Fix Error Cannot return null for non-nullable field Webhook.name. - #12989 by @cyborg7898- Remove unused `django-versatileimagefield` package - #13148 by @SzymJdiff --git a/poetry.lock b/poetry.lockindex a7c73b8896..263306bd61 100644--- a/poetry.lock+++ b/poetry.lock@@ -1312,22 +1312,6 @@ Django = ">=3.0,<5"enmerkar = ">=0.7.1"prices = ">=1.0.0"-[[package]]-name = "django-prices-openexchangerates"-version = "1.2.0"-description = "openexchangerates.org support for django-prices"-optional = false-python-versions = "*"-files = [- {file = "django-prices-openexchangerates-1.2.0.tar.gz", hash = "sha256:183cc2b6c15da7555d36b03634fef6c73c80e692a9f63ff0bfc1443f57f55740"},- {file = "django_prices_openexchangerates-1.2.0-py3-none-any.whl", hash = "sha256:2daff7ae82632ca4fd23e1b5328d9520b9d6a9f75e652f93ea8c8935d94f2baf"},-]--[package.dependencies]-Django = ">=3.0"-django-prices = ">=1.0.0"-prices = ">=1.0.0"-[[package]]name = "django-prices-vatlayer"version = "1.1.0"@@ -4920,4 +4904,4 @@ test = ["pytest"][metadata]lock-version = "2.0"python-versions = "~3.9"-content-hash = "ce6a6282bcaf681ee6d59154678d971fd17297d77ece3acd14788d2fd963c4aa"+content-hash = "3938ac24cfeaf676ba73ee59e01d26073b2c4c59ee759a597b41e543964486a7"diff --git a/pyproject.toml b/pyproject.tomlindex 939f4f3425..bbbd1e67ac 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -23,7 +23,6 @@ documentation = "https://docs.saleor.io/"django-mptt = "^0"django-phonenumber-field = ">=4,<8"django-prices = "^2.3"- django-prices-openexchangerates = "^1.2.0"django-prices-vatlayer = "^1.1.0"django-stubs-ext = "^4.2.1"draftjs-sanitizer = "^1.0.0"diff --git a/requirements.txt b/requirements.txtindex 41bfd2843d..a81e0b68fd 100644--- a/requirements.txt+++ b/requirements.txt@@ -44,7 +44,6 @@ django-js-asset==2.0.0 ; python_version >= "3.9" and python_version < "3.10"django-measurement==3.2.4 ; python_version >= "3.9" and python_version < "3.10"django-mptt==0.14.0 ; python_version >= "3.9" and python_version < "3.10"django-phonenumber-field==7.1.0 ; python_version >= "3.9" and python_version < "3.10"-django-prices-openexchangerates==1.2.0 ; python_version >= "3.9" and python_version < "3.10"django-prices-vatlayer==1.1.0 ; python_version >= "3.9" and python_version < "3.10"django-prices==2.3.0 ; python_version >= "3.9" and python_version < "3.10"django-redis==5.3.0 ; python_version >= "3.9" and python_version < "3.10"diff --git a/requirements_dev.txt b/requirements_dev.txtindex e3c5799626..e8f143eea7 100644--- a/requirements_dev.txt+++ b/requirements_dev.txt@@ -58,7 +58,6 @@ django-js-asset==2.0.0 ; python_version >= "3.9" and python_version < "3.10"django-measurement==3.2.4 ; python_version >= "3.9" and python_version < "3.10"django-mptt==0.14.0 ; python_version >= "3.9" and python_version < "3.10"django-phonenumber-field==7.1.0 ; python_version >= "3.9" and python_version < "3.10"-django-prices-openexchangerates==1.2.0 ; python_version >= "3.9" and python_version < "3.10"django-prices-vatlayer==1.1.0 ; python_version >= "3.9" and python_version < "3.10"django-prices==2.3.0 ; python_version >= "3.9" and python_version < "3.10"django-redis==5.3.0 ; python_version >= "3.9" and python_version < "3.10"diff --git a/saleor/core/tests/test_core.py b/saleor/core/tests/test_core.pyindex e6221469e8..cda31e609f 100644--- a/saleor/core/tests/test_core.py+++ b/saleor/core/tests/test_core.py@@ -6,7 +6,6 @@ from django.core.management import CommandError, call_commandfrom django.db.utils import DataErrorfrom django.templatetags.static import staticfrom django.test import RequestFactory, override_settings-from django_countries.fields import Countryfrom ...account.models import Address, Userfrom ...account.utils import create_superuser@@ -19,13 +18,7 @@ from ...product import ProductTypeKindfrom ...product.models import ProductTypefrom ...shipping.models import ShippingZonefrom ..storages import S3MediaStorage-from ..utils import (- build_absolute_uri,- generate_unique_slug,- get_client_ip,- get_currency_for_country,- random_data,-)+from ..utils import build_absolute_uri, generate_unique_slug, get_client_ip, random_datatype_schema = {"Vegetable": {@@ -62,15 +55,6 @@ def test_get_client_ip(ip_address, expected_ip):assert get_client_ip(request) == expected_ip- "country, expected_currency",- [(Country("PL"), "PLN"), (Country("US"), "USD"), (Country("GB"), "GBP")],-)-def test_get_currency_for_country(country, expected_currency, monkeypatch):- currency = get_currency_for_country(country.code)- assert currency == expected_currency--def test_create_superuser(db, client, media_root):credentials = {"email": "[email protected]", "password": "admin"}# Test admin creationdiff --git a/saleor/core/utils/__init__.py b/saleor/core/utils/__init__.pyindex ed4f7ff816..225130b226 100644--- a/saleor/core/utils/__init__.py+++ b/saleor/core/utils/__init__.py@@ -1,17 +1,13 @@-import osimport socket-from typing import TYPE_CHECKING, Iterable, Optional, TypeVar, Union+from typing import TYPE_CHECKING, Iterable, Optional, Unionfrom urllib.parse import urljoin-from babel.numbers import get_territory_currenciesfrom celery.utils.log import get_task_loggerfrom django.conf import settingsfrom django.contrib.sites.models import Sitefrom django.db.models import Modelfrom django.utils.encoding import iri_to_urifrom django.utils.text import slugify-from django_prices_openexchangerates import exchange_currency-from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRangefrom text_unidecode import unidecodetask_logger = get_task_logger(__name__)@@ -69,30 +65,6 @@ def is_valid_ipv6(ip: str) -> bool:return True-def get_currency_for_country(country_code: str):- currencies = get_territory_currencies(country_code)- if currencies:- return currencies[0]- return os.environ.get("DEFAULT_CURRENCY", "USD")---M = TypeVar("M", Money, MoneyRange, TaxedMoney, TaxedMoneyRange)---def to_local_currency(price: Optional[M], currency: str) -> Optional[M]:- if price is None:- return None- if not settings.OPENEXCHANGERATES_API_KEY: # type: ignore[misc] # circular import # noqa: E501- return None- from_currency = price.currency- if currency != from_currency:- try:- return exchange_currency(price, currency)- except ValueError:- pass- return None--def generate_unique_slug(instance: Model,slugable_value: str,diff --git a/saleor/graphql/product/tests/test_variant_pricing.py b/saleor/graphql/product/tests/test_variant_pricing.pyindex c52d1c35ed..34f4ea7199 100644--- a/saleor/graphql/product/tests/test_variant_pricing.py+++ b/saleor/graphql/product/tests/test_variant_pricing.py@@ -1,5 +1,5 @@from decimal import Decimal-from unittest.mock import Mock, patch+from unittest.mock import patchimport grapheneimport pytest@@ -148,24 +148,6 @@ def test_variant_pricing(prices_entered_with_tax=tc.prices_entered_with_tax,)assert pricing.price == taxed_price- assert pricing.price_local_currency is None-- monkeypatch.setattr(- "django_prices_openexchangerates.models.get_rates",- lambda c: {"PLN": Mock(rate=2)},- )-- settings.OPENEXCHANGERATES_API_KEY = "fake-key"-- pricing = get_variant_availability(- variant_channel_listing=variant_channel_listing,- product_channel_listing=product_channel_listing,- local_currency="PLN",- tax_rate=tax_rate,- tax_calculation_strategy=tc.tax_calculation_strategy,- prices_entered_with_tax=tc.prices_entered_with_tax,- )- assert pricing.price_local_currency.currency == "PLN" # type: ignorepricing = get_variant_availability(variant_channel_listing=variant_channel_listing,diff --git a/saleor/graphql/product/types/channels.py b/saleor/graphql/product/types/channels.pyindex ead2413135..e7ecd20659 100644--- a/saleor/graphql/product/types/channels.py+++ b/saleor/graphql/product/types/channels.py@@ -5,7 +5,6 @@ from typing import List, Optionalimport graphenefrom promise import Promise-from ....core.utils import get_currency_for_countryfrom ....graphql.core.types import Money, MoneyRangefrom ....permission.enums import ProductPermissionsfrom ....product import models@@ -241,7 +240,6 @@ class ProductChannelListing(ModelObjectType[models.ProductChannelListing]):def calculate_pricing_info(data):country_rates, default_country_rate_obj = data- local_currency = get_currency_for_country(country_code)tax_config_country = next((@@ -271,7 +269,6 @@ class ProductChannelListing(ModelObjectType[models.ProductChannelListing]):availability = get_product_availability(product_channel_listing=root,variants_channel_listing=variants_channel_listing,- local_currency=local_currency,prices_entered_with_tax=prices_entered_with_tax,tax_calculation_strategy=tax_calculation_strategy,tax_rate=tax_rate,diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex 312b51d9b9..e0e32a980e 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -9,7 +9,7 @@ from graphene import relayfrom promise import Promisefrom ....attribute import models as attribute_models-from ....core.utils import build_absolute_uri, get_currency_for_country+from ....core.utils import build_absolute_urifrom ....core.weight import convert_weight_to_default_weight_unitfrom ....permission.auth_filters import AuthorizationFiltersfrom ....permission.enums import OrderPermissions, ProductPermissions@@ -162,8 +162,12 @@ class BasePricingInfo(BaseObjectType):discount = graphene.Field(TaxedMoney, description="The discount amount if in sale (null otherwise).")++ # deprecateddiscount_local_currency = graphene.Field(- TaxedMoney, description="The discount amount in the local currency."+ TaxedMoney,+ description="The discount amount in the local currency.",+ deprecation_reason=f"{DEPRECATED_IN_3X_FIELD} Always returns `null`.",)class Meta:@@ -171,17 +175,23 @@ class BasePricingInfo(BaseObjectType):class VariantPricingInfo(BasePricingInfo):- discount_local_currency = graphene.Field(- TaxedMoney, description="The discount amount in the local currency."- )price = graphene.Field(TaxedMoney, description="The price, with any discount subtracted.")price_undiscounted = graphene.Field(TaxedMoney, description="The price without any discount.")++ # deprecated+ discount_local_currency = graphene.Field(+ TaxedMoney,+ description="The discount amount in the local currency.",+ deprecation_reason=f"{DEPRECATED_IN_3X_FIELD} Always returns `null`.",+ )price_local_currency = graphene.Field(- TaxedMoney, description="The discounted price in the local currency."+ TaxedMoney,+ description="The discounted price in the local currency.",+ deprecation_reason=f"{DEPRECATED_IN_3X_FIELD} Always returns `null`.",)class Meta:@@ -190,6 +200,13 @@ class VariantPricingInfo(BasePricingInfo):class ProductPricingInfo(BasePricingInfo):+ display_gross_prices = graphene.Boolean(+ description=(+ "Determines whether this product's price displayed in a storefront "+ "should include taxes." + ADDED_IN_39+ ),+ required=True,+ )price_range = graphene.Field(TaxedMoneyRange,description="The discounted price range of the product variants.",@@ -198,19 +215,15 @@ class ProductPricingInfo(BasePricingInfo):TaxedMoneyRange,description="The undiscounted price range of the product variants.",)++ # deprecatedprice_range_local_currency = graphene.Field(TaxedMoneyRange,description=("The discounted price range of the product variants ""in the local currency."),- )- display_gross_prices = graphene.Boolean(- description=(- "Determines whether this product's price displayed in a storefront "- "should include taxes." + ADDED_IN_39- ),- required=True,+ deprecation_reason=f"{DEPRECATED_IN_3X_FIELD} Always returns `null`.",)class Meta:@@ -594,7 +607,6 @@ class ProductVariant(ChannelContextTypeWithMetadata[models.ProductVariant]):def load_default_tax_rate(tax_configs_per_country):def calculate_pricing_info(data):country_rates, default_country_rate_obj = data- local_currency = get_currency_for_country(country_code)tax_config_country = next((@@ -620,7 +632,6 @@ class ProductVariant(ChannelContextTypeWithMetadata[models.ProductVariant]):availability = get_variant_availability(variant_channel_listing=variant_channel_listing,product_channel_listing=product_channel_listing,- local_currency=local_currency,prices_entered_with_tax=tax_config.prices_entered_with_tax,tax_calculation_strategy=tax_calculation_strategy,tax_rate=tax_rate,@@ -1097,7 +1108,6 @@ class Product(ChannelContextTypeWithMetadata[models.Product]):def load_default_tax_rate(tax_configs_per_country):def calculate_pricing_info(data):country_rates, default_country_rate_obj = data- local_currency = get_currency_for_country(country_code)tax_config_country = next((tc@@ -1126,7 +1136,6 @@ class Product(ChannelContextTypeWithMetadata[models.Product]):availability = get_product_availability(product_channel_listing=product_channel_listing,variants_channel_listing=variants_channel_listing,- local_currency=local_currency,prices_entered_with_tax=tax_config.prices_entered_with_tax,tax_calculation_strategy=tax_calculation_strategy,tax_rate=tax_rate,diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 50a21e0c01..be7e7f0af4 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -7126,7 +7126,7 @@ type VariantPricingInfo @doc(category: "Products") {discount: TaxedMoney"""The discount amount in the local currency."""- discountLocalCurrency: TaxedMoney+ discountLocalCurrency: TaxedMoney @deprecated(reason: "This field will be removed in Saleor 4.0. Always returns `null`.")"""The price, with any discount subtracted."""price: TaxedMoney@@ -7135,7 +7135,7 @@ type VariantPricingInfo @doc(category: "Products") {priceUndiscounted: TaxedMoney"""The discounted price in the local currency."""- priceLocalCurrency: TaxedMoney+ priceLocalCurrency: TaxedMoney @deprecated(reason: "This field will be removed in Saleor 4.0. Always returns `null`.")}"""@@ -7469,7 +7469,14 @@ type ProductPricingInfo @doc(category: "Products") {discount: TaxedMoney"""The discount amount in the local currency."""- discountLocalCurrency: TaxedMoney+ discountLocalCurrency: TaxedMoney @deprecated(reason: "This field will be removed in Saleor 4.0. Always returns `null`.")++ """+ Determines whether this product's price displayed in a storefront should include taxes.++ Added in Saleor 3.9.+ """+ displayGrossPrices: Boolean!"""The discounted price range of the product variants."""priceRange: TaxedMoneyRange@@ -7480,14 +7487,7 @@ type ProductPricingInfo @doc(category: "Products") {"""The discounted price range of the product variants in the local currency."""- priceRangeLocalCurrency: TaxedMoneyRange-- """- Determines whether this product's price displayed in a storefront should include taxes.-- Added in Saleor 3.9.- """- displayGrossPrices: Boolean!+ priceRangeLocalCurrency: TaxedMoneyRange @deprecated(reason: "This field will be removed in Saleor 4.0. Always returns `null`.")}"""Represents a range of monetary values."""diff --git a/saleor/product/tests/test_product_availability.py b/saleor/product/tests/test_product_availability.pyindex 0db79d68ba..4a6768be64 100644--- a/saleor/product/tests/test_product_availability.py+++ b/saleor/product/tests/test_product_availability.py@@ -1,6 +1,5 @@import datetimefrom decimal import Decimal-from unittest.mock import Mockfrom django.utils import timezonefrom freezegun import freeze_time@@ -40,23 +39,6 @@ def test_availability(stock, monkeypatch, settings, channel_USD):)taxed_price_range = TaxedMoneyRange(start=taxed_price, stop=taxed_price)assert availability.price_range == taxed_price_range- assert availability.price_range_local_currency is None-- monkeypatch.setattr(- "django_prices_openexchangerates.models.get_rates",- lambda c: {"PLN": Mock(rate=2)},- )- settings.DEFAULT_COUNTRY = "PL"- settings.OPENEXCHANGERATES_API_KEY = "fake-key"- availability = get_product_availability(- product_channel_listing=product_channel_listing,- variants_channel_listing=variants_channel_listing,- local_currency="PLN",- tax_rate=tax_rate,- tax_calculation_strategy=tc.tax_calculation_strategy,- prices_entered_with_tax=tc.prices_entered_with_tax,- )- assert availability.price_range_local_currency.start.currency == "PLN"availability = get_product_availability(product_channel_listing=product_channel_listing,diff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.pyindex 63f8bf44f6..e8a011d5b0 100644--- a/saleor/product/utils/availability.py+++ b/saleor/product/utils/availability.py@@ -1,10 +1,9 @@from dataclasses import dataclassfrom decimal import Decimal-from typing import List, Optional, Tuple+from typing import List, Optionalfrom prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange-from ...core.utils import to_local_currencyfrom ...product.models import ProductChannelListing, ProductVariantChannelListingfrom ...tax import TaxCalculationStrategyfrom ...tax.calculations import calculate_flat_rate_tax@@ -16,8 +15,6 @@ class ProductAvailability:price_range: Optional[TaxedMoneyRange]price_range_undiscounted: Optional[TaxedMoneyRange]discount: Optional[TaxedMoney]- price_range_local_currency: Optional[TaxedMoneyRange]- discount_local_currency: Optional[TaxedMoney]@dataclass@@ -26,8 +23,6 @@ class VariantAvailability:price: TaxedMoneyprice_undiscounted: TaxedMoneydiscount: Optional[TaxedMoney]- price_local_currency: Optional[TaxedMoney]- discount_local_currency: Optional[TaxedMoney]def _get_total_discount_from_range(@@ -54,27 +49,6 @@ def _get_total_discount(return None-def _get_product_price_range(- discounted: Optional[TaxedMoneyRange],- undiscounted: Optional[TaxedMoneyRange],- local_currency: Optional[str] = None,-) -> Tuple[Optional[TaxedMoneyRange], Optional[TaxedMoney]]:- price_range_local = None- discount_local_currency = None-- if local_currency:- price_range_local = to_local_currency(discounted, local_currency)- undiscounted_local = to_local_currency(undiscounted, local_currency)- if (- undiscounted_local- and price_range_local- and undiscounted_local.start > price_range_local.start- ):- discount_local_currency = undiscounted_local.start - price_range_local.start-- return price_range_local, discount_local_currency--def get_product_price_range(*,variants_channel_listing: List[ProductVariantChannelListing],@@ -117,7 +91,6 @@ def get_product_availability(*,product_channel_listing: Optional[ProductChannelListing],variants_channel_listing: List[ProductVariantChannelListing],- local_currency: Optional[str] = None,prices_entered_with_tax: bool,tax_calculation_strategy: str,tax_rate: Decimal@@ -164,13 +137,8 @@ def get_product_availability()discount = None- price_range_local = None- discount_local_currency = Noneif undiscounted is not None and discounted is not None:discount = _get_total_discount_from_range(undiscounted, discounted)- price_range_local, discount_local_currency = _get_product_price_range(- discounted, undiscounted, local_currency- )is_visible = (product_channel_listing is not None and product_channel_listing.is_visible@@ -182,8 +150,6 @@ def get_product_availability(price_range=discounted,price_range_undiscounted=undiscounted,discount=discount,- price_range_local_currency=price_range_local,- discount_local_currency=discount_local_currency,)@@ -191,7 +157,6 @@ def get_variant_availability(*,variant_channel_listing: ProductVariantChannelListing,product_channel_listing: Optional[ProductChannelListing],- local_currency: Optional[str] = None,prices_entered_with_tax: bool,tax_calculation_strategy: str,tax_rate: Decimal@@ -213,13 +178,6 @@ def get_variant_availability()discount = _get_total_discount(undiscounted_price_taxed, discounted_price_taxed)- if local_currency:- price_local_currency = to_local_currency(discounted_price_taxed, local_currency)- discount_local_currency = to_local_currency(discount, local_currency)- else:- price_local_currency = None- discount_local_currency = None-is_visible = (product_channel_listing is not None and product_channel_listing.is_visible)@@ -230,6 +188,4 @@ def get_variant_availability(price=discounted_price_taxed,price_undiscounted=undiscounted_price_taxed,discount=discount,- price_local_currency=price_local_currency,- discount_local_currency=discount_local_currency,)diff --git a/saleor/settings.py b/saleor/settings.pyindex 4c488b3b0a..594e0ac4b5 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -251,7 +251,6 @@ INSTALLED_APPS = [# External apps"django_measurement","django_prices",- "django_prices_openexchangerates","django_prices_vatlayer","mptt","django_countries",@@ -408,8 +407,6 @@ DEFAULT_MAX_EMAIL_DISPLAY_NAME_LENGTH = 78COUNTRIES_OVERRIDE = {"EU": "European Union"}-OPENEXCHANGERATES_API_KEY = os.environ.get("OPENEXCHANGERATES_API_KEY")-def get_host():from django.contrib.sites.models import Site