Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Apply changes after review
Maciej Korycinski51b1e17eb462
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a4283a79f3..825b03716d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,4 +1,3 @@-# ChangelogAll notable, unreleased changes to this project will be documented in this file. For the released changes, please visit the [Releases](https://github.com/mirumee/saleor/releases) page.diff --git a/saleor/plugins/vatlayer/__init__.py b/saleor/plugins/vatlayer/__init__.pyindex c6181e8f32..8681455bf8 100644--- a/saleor/plugins/vatlayer/__init__.py+++ b/saleor/plugins/vatlayer/__init__.py@@ -70,8 +70,8 @@ DEFAULT_TAX_RATE_NAME = TaxRateType.STANDARDclass VatlayerConfiguration:access_key: strexcluded_countries: Optional[List[str]]- countries_from_source: Optional[List[str]]- source_country: Optional[str]+ countries_from_origin: Optional[List[str]]+ origin_country: Optional[str]def _convert_to_naive_taxed_money(base, taxes, rate_name):diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex 08c0825b6b..c6eebbf467 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -2,6 +2,7 @@ from decimal import Decimalfrom typing import TYPE_CHECKING, Any, Iterable, List, Optional, Unionfrom django.conf import settings+from django.contrib.sites.models import Sitefrom django.core.exceptions import ValidationErrorfrom django_countries import countriesfrom django_countries.fields import Country@@ -52,33 +53,34 @@ class VatlayerPlugin(BasePlugin):DEFAULT_CONFIGURATION = [{"name": "Access key", "value": None},- {"name": "source_country", "value": None},- {"name": "countries_to_calculate_taxes_from_source", "value": None},+ {"name": "origin_country", "value": None},+ {"name": "countries_to_calculate_taxes_from_origin", "value": None},{"name": "excluded_countries", "value": None},]CONFIG_STRUCTURE = {- "source_country": {+ "origin_country": {"type": ConfigurationTypeField.STRING,"help_test": ("Country code in ISO format, required to calculate taxes for countries "- "from `Calculate taxes based on source country`."+ "from `Countries for which taxes will be calculated from origin "+ "country`."),- "label": "Source country",+ "label": "Origin country",},- "countries_to_calculate_taxes_from_source": {+ "countries_to_calculate_taxes_from_origin": {"type": ConfigurationTypeField.STRING,"help_text": (- "List of destination countries (separated by comma), in ISO format which "- "will use source country to calculate taxes."+ "List of destination countries (separated by comma), in ISO format "+ "which will use origin country to calculate taxes."),- "label": "Countries for which taxes will be calculated from source country",+ "label": "Countries for which taxes will be calculated from origin country",},"excluded_countries": {"type": ConfigurationTypeField.STRING,"help_text": (- "List of countries (separated by comma), in ISO format for which no VAT "- "should be added."+ "List of countries (separated by comma), in ISO format for which no "+ "VAT should be added."),"label": "Countries for which no VAT will be added.",},@@ -94,17 +96,17 @@ class VatlayerPlugin(BasePlugin):# Convert to dict to easier take config elementsconfiguration = {item["name"]: item["value"] for item in self.configuration}- source_country = configuration["source_country"] or ""- source_country = countries.alpha2(source_country.strip())+ origin_country = configuration["origin_country"] or ""+ origin_country = countries.alpha2(origin_country.strip())- countries_from_source = configuration[- "countries_to_calculate_taxes_from_source"+ countries_from_origin = configuration[+ "countries_to_calculate_taxes_from_origin"]- countries_from_source = countries_from_source or ""- countries_from_source = [- countries.alpha2(c.strip()) for c in countries_from_source.split(",")+ countries_from_origin = countries_from_origin or ""+ countries_from_origin = [+ countries.alpha2(c.strip()) for c in countries_from_origin.split(",")]- countries_from_source = list(filter(None, countries_from_source))+ countries_from_origin = list(filter(None, countries_from_origin))excluded_countries = configuration["excluded_countries"] or ""excluded_countries = [@@ -114,9 +116,9 @@ class VatlayerPlugin(BasePlugin):self.config = VatlayerConfiguration(access_key=configuration["Access key"],- source_country=source_country,+ origin_country=origin_country,excluded_countries=excluded_countries,- countries_from_source=countries_from_source,+ countries_from_origin=countries_from_origin,)self._cached_taxes = {}@@ -174,12 +176,20 @@ class VatlayerPlugin(BasePlugin):from cache or db."""if not country:- source_country_code = self.config.source_country or settings.DEFAULT_COUNTRY- country = Country(source_country_code)+ origin_country_code = self.config.origin_country+ if not origin_country_code:+ company_address = Site.objects.get_current().settings.company_address+ origin_country_code = (+ company_address.country+ if company_address+ else settings.DEFAULT_COUNTRY+ )++ country = Country(origin_country_code)country_code = country.code- if country_code in self.config.countries_from_source:- country_code = self.config.source_country+ if country_code in self.config.countries_from_origin:+ country_code = self.config.origin_countryif country_code in self.config.excluded_countries:return None@@ -524,16 +534,16 @@ class VatlayerPlugin(BasePlugin):)})- countries_from_source = configuration.get(- "countries_to_calculate_taxes_from_source"+ countries_from_origin = configuration.get(+ "countries_to_calculate_taxes_from_origin")- source_country = configuration.get("source_country")- if countries_from_source and not source_country:+ origin_country = configuration.get("origin_country")+ if countries_from_origin and not origin_country:raise ValidationError({- "source_country": ValidationError(+ "origin_country": ValidationError("Source country required when `Countries for which taxes will "- "be calculated from source country` provided.",+ "be calculated from origin country` provided.",code=PluginErrorCode.INVALID.value,)}diff --git a/saleor/plugins/vatlayer/tests/conftest.py b/saleor/plugins/vatlayer/tests/conftest.pyindex b3075bc824..cc70336fd4 100644--- a/saleor/plugins/vatlayer/tests/conftest.py+++ b/saleor/plugins/vatlayer/tests/conftest.py@@ -11,8 +11,8 @@ def vatlayer_plugin(settings, vatlayer):def fun(active=True,access_key="key",- source_country=None,- countries_to_calculate_taxes_from_source=None,+ origin_country=None,+ countries_to_calculate_taxes_from_origin=None,excluded_countries=None,):settings.PLUGINS = ["saleor.plugins.vatlayer.plugin.VatlayerPlugin"]@@ -24,10 +24,10 @@ def vatlayer_plugin(settings, vatlayer):"active": active,"configuration": [{"name": "Access key", "value": access_key},- {"name": "source_country", "value": source_country},+ {"name": "origin_country", "value": origin_country},{- "name": "countries_to_calculate_taxes_from_source",- "value": countries_to_calculate_taxes_from_source,+ "name": "countries_to_calculate_taxes_from_origin",+ "value": countries_to_calculate_taxes_from_origin,},{"name": "excluded_countries", "value": excluded_countries},],diff --git a/saleor/plugins/vatlayer/tests/test_vatlayer.py b/saleor/plugins/vatlayer/tests/test_vatlayer.pyindex 97ae244841..a4ac013c4d 100644--- a/saleor/plugins/vatlayer/tests/test_vatlayer.py+++ b/saleor/plugins/vatlayer/tests/test_vatlayer.py@@ -253,7 +253,7 @@ def test_calculate_checkout_total()-def test_calculate_checkout_total_from_source_country(+def test_calculate_checkout_total_from_origin_country(vatlayer_plugin,checkout_with_item,address,@@ -261,7 +261,7 @@ def test_calculate_checkout_total_from_source_country(discount_info,):plugin = vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -298,7 +298,7 @@ def test_calculate_checkout_total_with_excluded_country(shipping_zone,discount_info,):- plugin = vatlayer_plugin(source_country="PL", excluded_countries="PL,FR")+ plugin = vatlayer_plugin(origin_country="PL", excluded_countries="PL,FR")manager = get_plugins_manager()checkout_with_item.shipping_address = address@@ -374,7 +374,7 @@ def test_calculate_checkout_subtotal()-def test_calculate_checkout_subtotal_from_source_country(+def test_calculate_checkout_subtotal_from_origin_country(site_settings,vatlayer_plugin,checkout_with_item,@@ -383,7 +383,7 @@ def test_calculate_checkout_subtotal_from_source_country(discount_info,):plugin = vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -421,7 +421,7 @@ def test_calculate_checkout_subtotal_with_excluded_country(shipping_zone,discount_info,):- plugin = vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ plugin = vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()checkout_with_item.shipping_address = address@@ -461,11 +461,11 @@ def test_calculate_order_shipping(vatlayer, order_line, shipping_zone, site_settassert price == TaxedMoney(net=Money("8.13", "USD"), gross=Money("10.00", "USD"))-def test_calculate_order_shipping_from_source_country(+def test_calculate_order_shipping_from_origin_country(vatlayer_plugin, order_line, shipping_zone, site_settings):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -489,7 +489,7 @@ def test_calculate_order_shipping_from_source_country(def test_calculate_order_shipping_with_excluded_country(vatlayer_plugin, order_line, shipping_zone, site_settings):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()order = order_line.order@@ -544,11 +544,11 @@ def test_calculate_order_line_unit(vatlayer, order_line, shipping_zone, site_set)-def test_calculate_order_line_unit_from_source_country(+def test_calculate_order_line_unit_from_origin_country(vatlayer_plugin, order_line, shipping_zone, site_settings):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -581,7 +581,7 @@ def test_calculate_order_line_unit_from_source_country(def test_calculate_order_line_unit_with_excluded_country(vatlayer_plugin, order_line, shipping_zone, site_settings):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()order_line.unit_price = TaxedMoney(@@ -647,11 +647,11 @@ def test_calculate_checkout_line_total()-def test_calculate_checkout_line_total_from_source_country(+def test_calculate_checkout_line_total_from_origin_country(vatlayer_plugin, checkout_with_item, shipping_zone, address, site_settings):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -691,7 +691,7 @@ def test_calculate_checkout_line_total_from_source_country(def test_calculate_checkout_line_total_with_excluded_country(vatlayer_plugin, checkout_with_item, shipping_zone, address, site_settings):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()line = checkout_with_item.lines.first()@@ -775,11 +775,11 @@ def test_get_tax_rate_percentage_value(assert tax_rate == Decimal("23")-def test_get_tax_rate_percentage_value_from_source_country(+def test_get_tax_rate_percentage_value_from_origin_country(vatlayer_plugin, order_line, shipping_zone, site_settings, product):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -792,7 +792,7 @@ def test_get_tax_rate_percentage_value_from_source_country(def test_get_tax_rate_percentage_value_with_excluded_country(vatlayer_plugin, order_line, shipping_zone, site_settings, product):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()country = Country("PL")@@ -869,11 +869,11 @@ def test_apply_taxes_to_product(assert price == TaxedMoney(net=Money("4.07", "USD"), gross=Money("5.00", "USD"))-def test_apply_taxes_to_product_from_source_country(+def test_apply_taxes_to_product_from_origin_country(vatlayer_plugin, settings, variant, discount_info, channel_USD):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -899,7 +899,7 @@ def test_apply_taxes_to_product_from_source_country(def test_apply_taxes_to_product_with_excluded_country(vatlayer_plugin, settings, variant, discount_info, channel_USD):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()country = Country("PL")@@ -1049,7 +1049,7 @@ def test_get_checkout_line_tax_rate(assert tax_rate == Decimal("0.230")-def test_get_checkout_line_tax_rate_from_source_country(+def test_get_checkout_line_tax_rate_from_origin_country(site_settings,vatlayer_plugin,checkout_with_item,@@ -1057,7 +1057,7 @@ def test_get_checkout_line_tax_rate_from_source_country(shipping_zone,):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -1097,7 +1097,7 @@ def test_get_checkout_line_tax_rate_with_excluded_country(address,shipping_zone,):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()checkout_with_item.shipping_address = address@@ -1162,7 +1162,7 @@ def test_get_checkout_line_tax_rate_order_not_valid(assert tax_rate == Decimal("0.25")-def test_get_order_line_tax_rate_from_source_country(+def test_get_order_line_tax_rate_from_origin_country(site_settings,vatlayer_plugin,order_line,@@ -1170,7 +1170,7 @@ def test_get_order_line_tax_rate_from_source_country(shipping_zone,):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -1205,7 +1205,7 @@ def test_get_order_line_tax_rate_with_excluded_country(address,shipping_zone,):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()order = order_line.order@@ -1326,7 +1326,7 @@ def test_get_checkout_shipping_tax_rate(assert tax_rate == Decimal("0.230")-def test_get_checkout_shipping_tax_rate_from_source_country(+def test_get_checkout_shipping_tax_rate_from_origin_country(site_settings,vatlayer_plugin,checkout_with_item,@@ -1334,7 +1334,7 @@ def test_get_checkout_shipping_tax_rate_from_source_country(shipping_zone,):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -1373,7 +1373,7 @@ def test_get_checkout_shipping_tax_rate_with_excluded_country(address,shipping_zone,):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()checkout_with_item.shipping_address = address@@ -1504,7 +1504,7 @@ def test_get_order_shipping_tax_rate(assert tax_rate == Decimal("0.230")-def test_get_order_shipping_tax_rate_from_source_country(+def test_get_order_shipping_tax_rate_from_origin_country(site_settings,vatlayer_plugin,order_line,@@ -1512,7 +1512,7 @@ def test_get_order_shipping_tax_rate_from_source_country(shipping_zone,):vatlayer_plugin(- source_country="DE", countries_to_calculate_taxes_from_source="PL,FR"+ origin_country="DE", countries_to_calculate_taxes_from_origin="PL,FR")manager = get_plugins_manager()@@ -1545,7 +1545,7 @@ def test_get_order_shipping_tax_rate_with_excluded_country(address,shipping_zone,):- vatlayer_plugin(source_country="DE", excluded_countries="PL,FR")+ vatlayer_plugin(origin_country="DE", excluded_countries="PL,FR")manager = get_plugins_manager()order = order_line.order