Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Print vat percente for vatlayer on storefront
Maciej Korycinski7334a61b1cda
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.pyindex bcc5aa71f6..34bf737309 100644--- a/saleor/checkout/forms.py+++ b/saleor/checkout/forms.py@@ -8,7 +8,7 @@ from django.core.exceptions import NON_FIELD_ERRORS, ObjectDoesNotExistfrom django.utils.encoding import smart_textfrom django.utils.safestring import mark_safefrom django.utils.translation import npgettext_lazy, pgettext_lazy-from django_countries.fields import LazyTypedChoiceField+from django_countries.fields import Country, LazyTypedChoiceFieldfrom ..core.exceptions import InsufficientStockfrom ..core.taxes import display_gross_prices@@ -205,6 +205,8 @@ class CountryForm(forms.Form):country."""country = self.cleaned_data["country"]+ if isinstance(country, str):+ country = Country(country)return get_shipping_price_estimate(price, weight, country)diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex b26641f911..8c12d1096e 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -17,12 +17,12 @@ from ..account.utils import store_user_addressfrom ..core.exceptions import InsufficientStockfrom ..core.taxes import ZERO_MONEYfrom ..core.taxes.interface import (+ checkout_are_taxes_handled,get_line_total_gross,get_shipping_gross,get_subtotal_gross,get_total_gross,postprocess_order_creation,- show_taxes_on_storefront,)from ..core.utils import to_local_currencyfrom ..discount import VoucherType@@ -655,7 +655,7 @@ def get_checkout_context(checkout, discounts, currency=None, shipping_range=Nonecontext = {"checkout": checkout,- "checkout_are_taxes_handled": show_taxes_on_storefront(),+ "checkout_are_taxes_handled": checkout_are_taxes_handled(),"checkout_lines": [(line, get_line_total_gross(line, discounts)) for line in checkout],diff --git a/saleor/core/taxes/avatax/__init__.py b/saleor/core/taxes/avatax/__init__.pyindex c48c6b30b9..3b71b90a86 100644--- a/saleor/core/taxes/avatax/__init__.py+++ b/saleor/core/taxes/avatax/__init__.py@@ -82,6 +82,8 @@ def validate_checkout(checkout: "Checkout") -> bool:return Falseif not shipping_address:return False+ if not checkout.shipping_method:+ return Falsereturn Truediff --git a/saleor/core/taxes/interface.py b/saleor/core/taxes/interface.pyindex f202a52dc0..166b535527 100644--- a/saleor/core/taxes/interface.py+++ b/saleor/core/taxes/interface.py@@ -134,6 +134,14 @@ def show_taxes_on_storefront() -> bool:return False+def checkout_are_taxes_handled() -> bool:+ if settings.VATLAYER_ACCESS_KEY:+ return True+ if settings.AVATAX_USERNAME_OR_ACCOUNT and settings.AVATAX_PASSWORD_OR_LICENSE:+ return True+ return False++def apply_taxes_to_shipping_price_range(prices: MoneyRange, country: Country):if country:if settings.VATLAYER_ACCESS_KEY:diff --git a/saleor/core/taxes/vatlayer/interface.py b/saleor/core/taxes/vatlayer/interface.pyindex be56717ced..fede8a45a6 100644--- a/saleor/core/taxes/vatlayer/interface.py+++ b/saleor/core/taxes/vatlayer/interface.py@@ -47,6 +47,8 @@ def get_shipping_gross(checkout: "Checkout", _: "SaleQueryset") -> TaxedMoney:"""Calculate shipping gross for checkout"""address = checkout.shipping_address or checkout.billing_addresstaxes = get_taxes_for_address(address)+ if not checkout.shipping_method:+ return ZERO_TAXED_MONEYreturn get_taxed_shipping_price(checkout.shipping_method.price, taxes)diff --git a/saleor/product/utils/variants_picker.py b/saleor/product/utils/variants_picker.pyindex 1f49e0fd53..15844cad7e 100644--- a/saleor/product/utils/variants_picker.py+++ b/saleor/product/utils/variants_picker.py@@ -4,12 +4,15 @@ from django_prices.templatetags import prices_i18nfrom ...core.taxes import display_gross_pricesfrom ...core.taxes.interface import apply_taxes_to_variant, show_taxes_on_storefront+from ...core.taxes.vatlayer import get_tax_rate_by_namefrom ...core.utils import to_local_currencyfrom ...seo.schema.product import variant_json_ldfrom .availability import get_product_availability-def get_variant_picker_data(product, discounts=None, country=None, local_currency=None):+def get_variant_picker_data(+ product, discounts=None, taxes=None, local_currency=None, country=None+):availability = get_product_availability(product, discounts, country, local_currency)variants = product.variants.all()data = {"variantAttributes": [], "variants": []}@@ -68,7 +71,8 @@ def get_variant_picker_data(product, discounts=None, country=None, local_currencdata["availability"] = {"discount": price_as_dict(availability.discount),- "taxRate": 0,+ # FIXME this should use plugin hooks after we will introduce plugin architecure.+ "taxRate": get_tax_rate_by_name(product.tax_rate, taxes),"priceRange": price_range_as_dict(availability.price_range),"priceRangeUndiscounted": price_range_as_dict(availability.price_range_undiscounteddiff --git a/saleor/product/views.py b/saleor/product/views.pyindex fb0ea42d1e..cb8951adc7 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -83,7 +83,7 @@ def product_details(request, slug, product_id, form=None):)product_images = get_product_images(product)variant_picker_data = get_variant_picker_data(- product, request.discounts, request.country, request.currency+ product, request.discounts, request.taxes, request.currency, request.country)product_attributes = get_product_attributes_data(product)# show_variant_picker determines if variant picker is used or select input