Skip to content

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

Drop vatlayer package (#13179)

Marcin Gębalaed59e7d6ab09
diff --git a/poetry.lock b/poetry.lock
index 263306bd61..1fdf15b860 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1312,23 +1312,6 @@ Django = ">=3.0,<5"
enmerkar = ">=0.7.1"
prices = ">=1.0.0"
-[[package]]
-name = "django-prices-vatlayer"
-version = "1.1.0"
-description = "vatlayer.com support for django"
-optional = false
-python-versions = "*"
-files = [
- {file = "django-prices-vatlayer-1.1.0.tar.gz", hash = "sha256:54cb240dfd2b7c5fd22498aaf6e9141e602eccb2b0672911c64dc5add3fa666e"},
- {file = "django_prices_vatlayer-1.1.0-py3-none-any.whl", hash = "sha256:de47234d46ae35d83dd35adbd83e3d26a9c90a8d184020590109bdef39474ed0"},
-]
-
-[package.dependencies]
-Django = ">=1.11"
-jsonfield = "*"
-prices = ">=1.0.0"
-requests = "*"
-
[[package]]
name = "django-redis"
version = "5.3.0"
@@ -2314,20 +2297,6 @@ files = [
{file = "jmespath-1.0.1.tar.gz", hash = "sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe"},
]
-[[package]]
-name = "jsonfield"
-version = "3.1.0"
-description = "A reusable Django field that allows you to store validated JSON in your model."
-optional = false
-python-versions = ">=3.6"
-files = [
- {file = "jsonfield-3.1.0-py3-none-any.whl", hash = "sha256:df857811587f252b97bafba42e02805e70a398a7a47870bc6358a0308dd689ed"},
- {file = "jsonfield-3.1.0.tar.gz", hash = "sha256:7e4e84597de21eeaeeaaa7cc5da08c61c48a9b64d0c446b2d71255d01812887a"},
-]
-
-[package.dependencies]
-Django = ">=2.2"
-
[[package]]
name = "kombu"
version = "5.3.1"
@@ -4904,4 +4873,4 @@ test = ["pytest"]
[metadata]
lock-version = "2.0"
python-versions = "~3.9"
-content-hash = "3938ac24cfeaf676ba73ee59e01d26073b2c4c59ee759a597b41e543964486a7"
+content-hash = "a2dbada6b13fa41ce168f34715c6bfd7f3322e0b85d93f4b0a85ee543cfbc1ed"
diff --git a/pyproject.toml b/pyproject.toml
index bbbd1e67ac..8801351e55 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-vatlayer = "^1.1.0"
django-stubs-ext = "^4.2.1"
draftjs-sanitizer = "^1.0.0"
faker = ">=4.1,<19.0"
diff --git a/requirements.txt b/requirements.txt
index a81e0b68fd..a5f5674c3e 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-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"
django-storages[google]==1.13.2 ; python_version >= "3.9" and python_version < "3.10"
@@ -87,7 +86,6 @@ importlib-metadata==6.7.0 ; python_version >= "3.9" and python_version < "3.10"
isodate==0.6.1 ; python_version >= "3.9" and python_version < "3.10"
jaeger-client==4.8.0 ; python_version >= "3.9" and python_version < "3.10"
jmespath==1.0.1 ; python_version >= "3.9" and python_version < "3.10"
-jsonfield==3.1.0 ; python_version >= "3.9" and python_version < "3.10"
kombu==5.3.1 ; python_version >= "3.9" and python_version < "3.10"
lxml==4.9.2 ; python_version >= "3.9" and python_version < "3.10"
markdown==3.4.3 ; python_version >= "3.9" and python_version < "3.10"
diff --git a/requirements_dev.txt b/requirements_dev.txt
index e8f143eea7..9a33cbe4bd 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-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"
django-storages[google]==1.13.2 ; python_version >= "3.9" and python_version < "3.10"
@@ -111,7 +110,6 @@ isort==5.12.0 ; python_version >= "3.9" and python_version < "3.10"
jaeger-client==4.8.0 ; python_version >= "3.9" and python_version < "3.10"
jinja2==3.1.2 ; python_version >= "3.9" and python_version < "3.10"
jmespath==1.0.1 ; python_version >= "3.9" and python_version < "3.10"
-jsonfield==3.1.0 ; python_version >= "3.9" and python_version < "3.10"
kombu==5.3.1 ; python_version >= "3.9" and python_version < "3.10"
lazy-object-proxy==1.9.0 ; python_version >= "3.9" and python_version < "3.10"
lxml==4.9.2 ; python_version >= "3.9" and python_version < "3.10"
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
index 0cd62bebac..fd9d4c5721 100644
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -116,8 +116,8 @@ class CountryDisplay(graphene.ObjectType):
VAT,
description="Country tax.",
deprecation_reason=(
- f"{DEPRECATED_IN_3X_FIELD} Use `TaxClassCountryRate` type to manage tax "
- "rates per country."
+ f"{DEPRECATED_IN_3X_FIELD} Always returns `null`. Use `TaxClassCountryRate`"
+ " type to manage tax rates per country."
),
)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 0a366a4cf7..db86aa397f 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -3638,7 +3638,7 @@ type CountryDisplay {
country: String!
"""Country tax."""
- vat: VAT @deprecated(reason: "This field will be removed in Saleor 4.0. Use `TaxClassCountryRate` type to manage tax rates per country.")
+ vat: VAT @deprecated(reason: "This field will be removed in Saleor 4.0. Always returns `null`. Use `TaxClassCountryRate` type to manage tax rates per country.")
}
"""Represents a VAT rate for a country."""
diff --git a/saleor/graphql/shop/resolvers.py b/saleor/graphql/shop/resolvers.py
index 9c6c7ed430..1531cf3162 100644
--- a/saleor/graphql/shop/resolvers.py
+++ b/saleor/graphql/shop/resolvers.py
@@ -1,6 +1,5 @@
from django.utils import translation
from django_countries import countries
-from django_prices_vatlayer.models import VAT
from ...account.models import Address
from ...shipping.models import ShippingMethod, ShippingMethodChannelListing
@@ -37,14 +36,11 @@ def resolve_countries(**kwargs):
countries_filter = kwargs.get("filter", {})
attached_to_shipping_zones = countries_filter.get("attached_to_shipping_zones")
language_code = kwargs.get("language_code")
- taxes = {vat.country_code: vat for vat in VAT.objects.all()}
codes_list = get_countries_codes_list(attached_to_shipping_zones)
# DEPRECATED: translation.override will be dropped in Saleor 4.0
with translation.override(language_code):
return [
- CountryDisplay(
- code=country[0], country=country[1], vat=taxes.get(country[0])
- )
+ CountryDisplay(code=country[0], country=country[1], vat=None)
for country in countries
if country[0] in codes_list
]
diff --git a/saleor/graphql/shop/tests/test_shop_taxes.py b/saleor/graphql/shop/tests/test_shop_taxes.py
deleted file mode 100644
index ab49316cca..0000000000
--- a/saleor/graphql/shop/tests/test_shop_taxes.py
+++ /dev/null
@@ -1,139 +0,0 @@
-import pytest
-from django_prices_vatlayer.models import VAT
-from django_prices_vatlayer.utils import get_tax_for_rate
-
-from ...tests.utils import get_graphql_content
-
-# FIXME we are going to rewrite tax section. Currently, below tests are connected only
-# with vatlayer. After we introduce approach for taxes and API, we should rebuild this
-# tests.
-
-
-def tax_rates():
- return {
- "standard_rate": 23,
- "reduced_rates": {
- "pharmaceuticals": 8,
- "medical": 8,
- "passenger transport": 8,
- "newspapers": 8,
- "hotels": 8,
- "restaurants": 8,
- "admission to cultural events": 8,
- "admission to sporting events": 8,
- "admission to entertainment events": 8,
- "foodstuffs": 5,
- },
- }
-
-
-def taxes(tax_rates):
- taxes = {
- "standard": {
- "value": tax_rates["standard_rate"],
- "tax": get_tax_for_rate(tax_rates),
- }
- }
- if tax_rates["reduced_rates"]:
- taxes.update(
- {
- rate: {
- "value": tax_rates["reduced_rates"][rate],
- "tax": get_tax_for_rate(tax_rates, rate),
- }
- for rate in tax_rates["reduced_rates"]
- }
- )
- return taxes
-
-
-def vatlayer(db, tax_rates, taxes):
- VAT.objects.create(country_code="PL", data=tax_rates)
-
- tax_rates_2 = {
- "standard_rate": 19,
- "reduced_rates": {
- "admission to cultural events": 7,
- "admission to entertainment events": 7,
- "books": 7,
- "foodstuffs": 7,
- "hotels": 7,
- "medical": 7,
- "newspapers": 7,
- "passenger transport": 7,
- },
- }
- VAT.objects.create(country_code="DE", data=tax_rates_2)
- return taxes
-
-
-def test_query_countries_with_tax(user_api_client, vatlayer, tax_rates):
- # given
- query = """
- query {
- shop {
- countries {
- code
- vat {
- standardRate
- reducedRates {
- rate
- rateType
- }
- }
- }
- }
- }
- """
-
- # when
- response = user_api_client.post_graphql(query)
-
- # then
- content = get_graphql_content(response)
- data = content["data"]["shop"]["countries"]
- vat = VAT.objects.first()
- country = next(country for country in data if country["code"] == vat.country_code)
-
- rates_from_response = set(
- [(rate["rateType"], rate["rate"]) for rate in country["vat"]["reducedRates"]]
- )
-
- reduced_rates = set(
- [
- (tax_rate, tax_rates["reduced_rates"][tax_rate])
- for tax_rate in tax_rates["reduced_rates"]
- ]
- )
-
- assert country["vat"]["standardRate"] == tax_rates["standard_rate"]
- assert rates_from_response == reduced_rates
-
-
-def test_query_default_country_with_tax(user_api_client, settings, vatlayer, tax_rates):
- # given
- settings.DEFAULT_COUNTRY = "PL"
- query = """
- query {
- shop {
- defaultCountry {
- code
- vat {
- standardRate
- }
- }
- }
- }
- """
-
- # when
- response = user_api_client.post_graphql(query)
-
- # then
- content = get_graphql_content(response)
- data = content["data"]["shop"]["defaultCountry"]
- assert data["code"] == settings.DEFAULT_COUNTRY
- assert data["vat"]["standardRate"] == tax_rates["standard_rate"]
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
index 81771c7db2..dbd811c3db 100644
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -3,7 +3,6 @@ from typing import Optional
import graphene
from django.conf import settings
from django_countries import countries
-from django_prices_vatlayer.models import VAT
from phonenumbers import COUNTRY_CODE_TO_REGION_CODE
from ... import __version__, schema_version
@@ -455,9 +454,8 @@ class Shop(graphene.ObjectType):
default_country_code = settings.DEFAULT_COUNTRY
default_country_name = countries.countries.get(default_country_code)
if default_country_name:
- vat = VAT.objects.filter(country_code=default_country_code).first()
default_country = CountryDisplay(
- code=default_country_code, country=default_country_name, vat=vat
+ code=default_country_code, country=default_country_name, vat=None
)
else:
default_country = None
diff --git a/saleor/settings.py b/saleor/settings.py
index 594e0ac4b5..e54f36486e 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -251,7 +251,6 @@ INSTALLED_APPS = [
# External apps
"django_measurement",
"django_prices",
- "django_prices_vatlayer",
"mptt",
"django_countries",
"django_filters",
diff --git a/saleor/tax/migrations/0005_migrate_vatlayer.py b/saleor/tax/migrations/0005_migrate_vatlayer.py
index 76a6e4625f..45c64298c8 100644
--- a/saleor/tax/migrations/0005_migrate_vatlayer.py
+++ b/saleor/tax/migrations/0005_migrate_vatlayer.py
@@ -63,10 +63,17 @@ def create_tax_configurations(apps, vatlayer_configs):
def create_tax_rates(apps, use_origin_country_map):
TaxClass = apps.get_model("tax", "TaxClass")
TaxClassCountryRate = apps.get_model("tax", "TaxClassCountryRate")
- VAT = apps.get_model("django_prices_vatlayer", "VAT")
tax_classes = TaxClass.objects.exclude(name=TAX_CLASS_ZERO_RATE)
- vat_rates = VAT.objects.all()
+
+ # django_prices_vatlayer is removed in Saleor 3.15; if it's not installed, we're
+ # skipping this part of the migration.
+ try:
+ VAT = apps.get_model("django_prices_vatlayer", "VAT")
+ except LookupError:
+ vat_rates = []
+ else:
+ vat_rates = VAT.objects.all()
rates = {}
for tax_class in tax_classes: