Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Handle a new tax types categories returned by vatlayer (#7356)
Maciej Korycinski217de10463e9
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.pyindex cd7ee83af4..e24e3c5dfa 100644--- a/saleor/graphql/core/enums.py+++ b/saleor/graphql/core/enums.py@@ -25,7 +25,6 @@ from ...order import error_codes as order_error_codesfrom ...page import error_codes as page_error_codesfrom ...payment import error_codes as payment_error_codesfrom ...plugins import error_codes as plugin_error_codes-from ...plugins.vatlayer import TaxRateType as CoreTaxRateTypefrom ...product import error_codes as product_error_codesfrom ...shipping import error_codes as shipping_error_codesfrom ...warehouse import error_codes as warehouse_error_codes@@ -34,9 +33,6 @@ from ...wishlist import error_codes as wishlist_error_codesfrom ..shop import error_codes as shop_error_codesfrom .utils import str_to_enum-# FIXME CoreTaxRateType should be removed after we will drop old api fields dedicated-# to taxes-class OrderDirection(graphene.Enum):ASC = ""@@ -90,9 +86,6 @@ LanguageCodeEnum = graphene.Enum([(lang[0].replace("-", "_").upper(), lang[0]) for lang in settings.LANGUAGES],)-TaxRateType = graphene.Enum(- "TaxRateType", [(str_to_enum(rate[0]), rate[0]) for rate in CoreTaxRateType.CHOICES]-)JobStatusEnum = to_enum(JobStatus)PermissionEnum = graphene.Enum("PermissionEnum", get_permissions_enum_list())diff --git a/saleor/graphql/core/types/money.py b/saleor/graphql/core/types/money.pyindex 9826fa9b8a..f57bad2542 100644--- a/saleor/graphql/core/types/money.py+++ b/saleor/graphql/core/types/money.py@@ -3,7 +3,6 @@ from django_prices.templatetags import pricesfrom ....core.prices import quantize_pricefrom ....core.tracing import traced_resolver-from ..enums import TaxRateTypeclass Money(graphene.ObjectType):@@ -86,7 +85,7 @@ class VAT(graphene.ObjectType):class ReducedRate(graphene.ObjectType):rate = graphene.Float(description="Reduced VAT rate in percent.", required=True)- rate_type = TaxRateType(description="A type of goods.", required=True)+ rate_type = graphene.String(description="A type of goods.", required=True)class Meta:description = "Represents a reduced VAT rate for a particular type of goods."diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex eacc7ff906..736cc4379e 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -4766,7 +4766,7 @@ type Query {type ReducedRate {rate: Float!- rateType: TaxRateType!+ rateType: String!}type RefreshToken {@@ -5450,34 +5450,6 @@ input StockInput {quantity: Int!}-enum TaxRateType {- ACCOMMODATION- ADMISSION_TO_CULTURAL_EVENTS- ADMISSION_TO_ENTERTAINMENT_EVENTS- ADMISSION_TO_SPORTING_EVENTS- ADVERTISING- AGRICULTURAL_SUPPLIES- BABY_FOODSTUFFS- BIKES- BOOKS- CHILDRENS_CLOTHING- DOMESTIC_FUEL- DOMESTIC_SERVICES- E_BOOKS- FOODSTUFFS- HOTELS- MEDICAL- NEWSPAPERS- PASSENGER_TRANSPORT- PHARMACEUTICALS- PROPERTY_RENOVATIONS- RESTAURANTS- SOCIAL_HOUSING- STANDARD- WATER- WINE-}-type TaxType {description: StringtaxCode: Stringdiff --git a/saleor/graphql/shop/tests/test_shop_taxes.py b/saleor/graphql/shop/tests/test_shop_taxes.pyindex 8cd9a42aae..d17d4752f3 100644--- a/saleor/graphql/shop/tests/test_shop_taxes.py+++ b/saleor/graphql/shop/tests/test_shop_taxes.py@@ -4,7 +4,6 @@ import pytestfrom django_prices_vatlayer.models import VATfrom django_prices_vatlayer.utils import get_tax_for_rate-from ...core.utils import str_to_enumfrom ...tests.utils import get_graphql_content# FIXME we are going to rewrite tax section. Currently, below tests are connected only@@ -95,13 +94,20 @@ def test_query_countries_with_tax(user_api_client, vatlayer, tax_rates):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"]- rates = {rate["rateType"]: rate["rate"] for rate in country["vat"]["reducedRates"]}- reduced_rates = {- str_to_enum(tax_rate): tax_rates["reduced_rates"][tax_rate]- for tax_rate in tax_rates["reduced_rates"]- }- assert rates == reduced_rates+ assert rates_from_response == reduced_ratesdef test_query_default_country_with_tax(user_api_client, settings, vatlayer, tax_rates):diff --git a/saleor/plugins/vatlayer/__init__.py b/saleor/plugins/vatlayer/__init__.pyindex 8681455bf8..2192780c9f 100644--- a/saleor/plugins/vatlayer/__init__.py+++ b/saleor/plugins/vatlayer/__init__.py@@ -6,64 +6,7 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRangefrom ...core.taxes import charge_taxes_on_shipping, include_taxes_in_prices--class TaxRateType:- ACCOMMODATION = "accommodation"- ADMISSION_TO_CULTURAL_EVENTS = "admission to cultural events"- ADMISSION_TO_ENTERTAINMENT_EVENTS = "admission to entertainment events"- ADMISSION_TO_SPORTING_EVENTS = "admission to sporting events"- ADVERTISING = "advertising"- AGRICULTURAL_SUPPLIES = "agricultural supplies"- BABY_FOODSTUFFS = "baby foodstuffs"- BIKES = "bikes"- BOOKS = "books"- CHILDRENDS_CLOTHING = "childrens clothing"- DOMESTIC_FUEL = "domestic fuel"- DOMESTIC_SERVICES = "domestic services"- E_BOOKS = "e-books"- FOODSTUFFS = "foodstuffs"- HOTELS = "hotels"- MEDICAL = "medical"- NEWSPAPERS = "newspapers"- PASSENGER_TRANSPORT = "passenger transport"- PHARMACEUTICALS = "pharmaceuticals"- PROPERTY_RENOVATIONS = "property renovations"- RESTAURANTS = "restaurants"- SOCIAL_HOUSING = "social housing"- STANDARD = "standard"- WATER = "water"- WINE = "wine"-- CHOICES = (- (ACCOMMODATION, "accommodation"),- (ADMISSION_TO_CULTURAL_EVENTS, "admission to cultural events"),- (ADMISSION_TO_ENTERTAINMENT_EVENTS, "admission to entertainment events"),- (ADMISSION_TO_SPORTING_EVENTS, "admission to sporting events"),- (ADVERTISING, "advertising"),- (AGRICULTURAL_SUPPLIES, "agricultural supplies"),- (BABY_FOODSTUFFS, "baby foodstuffs"),- (BIKES, "bikes"),- (BOOKS, "books"),- (CHILDRENDS_CLOTHING, "childrens clothing"),- (DOMESTIC_FUEL, "domestic fuel"),- (DOMESTIC_SERVICES, "domestic services"),- (E_BOOKS, "e-books"),- (FOODSTUFFS, "foodstuffs"),- (HOTELS, "hotels"),- (MEDICAL, "medical"),- (NEWSPAPERS, "newspapers"),- (PASSENGER_TRANSPORT, "passenger transport"),- (PHARMACEUTICALS, "pharmaceuticals"),- (PROPERTY_RENOVATIONS, "property renovations"),- (RESTAURANTS, "restaurants"),- (SOCIAL_HOUSING, "social housing"),- (STANDARD, "standard"),- (WATER, "water"),- (WINE, "wine"),- )---DEFAULT_TAX_RATE_NAME = TaxRateType.STANDARD+DEFAULT_TAX_RATE_NAME = "standard"@dataclassdiff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex 0fd2e610e3..e0a477a3e8 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -21,7 +21,6 @@ from ..base_plugin import BasePlugin, ConfigurationTypeFieldfrom ..manager import get_plugins_managerfrom . import (DEFAULT_TAX_RATE_NAME,- TaxRateType,VatlayerConfiguration,apply_tax_to_price,get_taxed_shipping_price,@@ -489,9 +488,6 @@ class VatlayerPlugin(BasePlugin):obj.delete_value_from_metadata(self.META_DESCRIPTION_KEY)return previous_value- if tax_code not in dict(TaxRateType.CHOICES):- return previous_value-tax_item = {self.META_CODE_KEY: tax_code, self.META_DESCRIPTION_KEY: tax_code}obj.store_value_in_metadata(items=tax_item)return previous_value