Skip to content

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

Remove most of the fixme problems

Maciej Korycinski671853119827
diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py
index f319d985ec..e2d512343a 100644
--- a/saleor/core/__init__.py
+++ b/saleor/core/__init__.py
@@ -1,6 +1,5 @@
from django.conf import settings
from django.core.checks import Warning, register
-from django.utils.translation import pgettext_lazy
TOKEN_PATTERN = (
"(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}" "-[0-9a-z]{12})"
@@ -27,71 +26,3 @@ def check_session_caching(app_configs, **kwargs): # pragma: no cover
)
)
return errors
-
-
-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, pgettext_lazy("VAT rate type", "accommodation")),
- (
- ADMISSION_TO_CULTURAL_EVENTS,
- pgettext_lazy("VAT rate type", "admission to cultural events"),
- ),
- (
- ADMISSION_TO_ENTERTAINMENT_EVENTS,
- pgettext_lazy("VAT rate type", "admission to entertainment events"),
- ),
- (
- ADMISSION_TO_SPORTING_EVENTS,
- pgettext_lazy("VAT rate type", "admission to sporting events"),
- ),
- (ADVERTISING, pgettext_lazy("VAT rate type", "advertising")),
- (
- AGRICULTURAL_SUPPLIES,
- pgettext_lazy("VAT rate type", "agricultural supplies"),
- ),
- (BABY_FOODSTUFFS, pgettext_lazy("VAT rate type", "baby foodstuffs")),
- (BIKES, pgettext_lazy("VAT rate type", "bikes")),
- (BOOKS, pgettext_lazy("VAT rate type", "books")),
- (CHILDRENDS_CLOTHING, pgettext_lazy("VAT rate type", "childrens clothing")),
- (DOMESTIC_FUEL, pgettext_lazy("VAT rate type", "domestic fuel")),
- (DOMESTIC_SERVICES, pgettext_lazy("VAT rate type", "domestic services")),
- (E_BOOKS, pgettext_lazy("VAT rate type", "e-books")),
- (FOODSTUFFS, pgettext_lazy("VAT rate type", "foodstuffs")),
- (HOTELS, pgettext_lazy("VAT rate type", "hotels")),
- (MEDICAL, pgettext_lazy("VAT rate type", "medical")),
- (NEWSPAPERS, pgettext_lazy("VAT rate type", "newspapers")),
- (PASSENGER_TRANSPORT, pgettext_lazy("VAT rate type", "passenger transport")),
- (PHARMACEUTICALS, pgettext_lazy("VAT rate type", "pharmaceuticals")),
- (PROPERTY_RENOVATIONS, pgettext_lazy("VAT rate type", "property renovations")),
- (RESTAURANTS, pgettext_lazy("VAT rate type", "restaurants")),
- (SOCIAL_HOUSING, pgettext_lazy("VAT rate type", "social housing")),
- (STANDARD, pgettext_lazy("VAT rate type", "standard")),
- (WATER, pgettext_lazy("VAT rate type", "water")),
- (WINE, pgettext_lazy("VAT rate type", "wine")),
- )
diff --git a/saleor/core/taxes/avatax/__init__.py b/saleor/core/taxes/avatax/__init__.py
index 528151d96a..14ed02a74a 100644
--- a/saleor/core/taxes/avatax/__init__.py
+++ b/saleor/core/taxes/avatax/__init__.py
@@ -7,6 +7,7 @@ from urllib.parse import urljoin
import requests
from django.conf import settings
from django.core.cache import cache
+from django.utils.translation import pgettext_lazy
from requests.auth import HTTPBasicAuth
from saleor.core.utils import get_company_address
@@ -27,6 +28,20 @@ class TransactionType:
ORDER = "SalesOrder"
+class CustomerErrors:
+ DEFAULT_MSG = pgettext_lazy(
+ "We are not able to calculate taxes for your order. Please try later"
+ )
+ ERRORS = ("InvalidPostalCode", "InvalidAddress", "MissingAddress")
+
+ @classmethod
+ def get_error_msg(cls, error: dict) -> str:
+ error_code = error.get("code")
+ if error_code in cls.ERRORS:
+ return error.get("message", cls.DEFAULT_MSG)
+ return cls.DEFAULT_MSG
+
+
def get_api_url() -> str:
"""Based on settings return sanbox or production url"""
if settings.AVATAX_USE_SANDBOX:
@@ -141,7 +156,6 @@ def append_line_to_data(
"amount": str(amount),
"taxCode": tax_code,
"taxIncluded": include_taxes_in_prices(),
- # FIXME Should fetch taxcode from somewhere and save inside variant/product
"itemCode": item_code,
"description": description[:2000] if description else "",
}
@@ -226,6 +240,7 @@ def generate_request_data(
customer_code: Optional[int],
customer_email: str,
commit=False,
+ currency=settings.DEFAULT_CURRENCY,
):
company_address = get_company_address()
if company_address:
@@ -244,15 +259,8 @@ def generate_request_data(
"code": transaction_token,
"date": str(date.today()),
"customerCode": customer_code,
- # 'salespersonCode'
- # 'customerUsageType'
- # 'entityUseCode'
- # 'discount'
- # 'purchaseOrderNo'
- # 'exemptionNo'
"addresses": {
- # FIXME we should put company address here
- "shipFrom": { # warehouse
+ "shipFrom": {
"line1": company_address.get("street_address_1"),
"line2": company_address.get("street_address_2"),
"city": company_address.get("city"),
@@ -269,14 +277,8 @@ def generate_request_data(
"postalCode": address.get("postal_code"),
},
},
- # parameters
- # referenceCode
- # reportingLocationCode
- # isSellerImporterOfRecord
- # businessIdentificationNo
"commit": commit,
- # batchCode
- "currencyCode": settings.DEFAULT_CURRENCY,
+ "currencyCode": currency,
"email": customer_email,
}
return {"createTransactionModel": data}
@@ -304,11 +306,11 @@ def generate_request_data_from_checkout(
return data
-def get_cached_response_or_fetch(data, token_in_cache):
+def get_cached_response_or_fetch(data, token_in_cache, force_refresh=False):
"""Try to find response in cache. Return cached response if requests data are
the same. Fetch new data in other cases"""
data_cache_key = settings.AVATAX_CACHE_KEY + token_in_cache
- if taxes_need_new_fetch(data, token_in_cache):
+ if taxes_need_new_fetch(data, token_in_cache) or force_refresh:
transaction_url = urljoin(get_api_url(), "transactions/createoradjust")
print("HIT TO API")
response = api_post_request(transaction_url, data)
@@ -328,7 +330,9 @@ def get_checkout_tax_data(checkout: "Checkout", discounts) -> Dict[str, Any]:
return get_cached_response_or_fetch(data, str(checkout.token))
-def get_order_tax_data(order: "Order", commit=False) -> Dict[str, Any]:
+def get_order_tax_data(
+ order: "Order", commit=False, force_refresh=False
+) -> Dict[str, Any]:
address = order.shipping_address or order.billing_address
lines = get_order_lines_data(order)
transaction = (
@@ -343,7 +347,9 @@ def get_order_tax_data(order: "Order", commit=False) -> Dict[str, Any]:
customer_email=order.user_email,
commit=commit,
)
- response = get_cached_response_or_fetch(data, "order_%s" % order.token)
+ response = get_cached_response_or_fetch(
+ data, "order_%s" % order.token, force_refresh
+ )
return response
diff --git a/saleor/core/taxes/avatax/interface.py b/saleor/core/taxes/avatax/interface.py
index c6098ee8c2..b8ac0e58da 100644
--- a/saleor/core/taxes/avatax/interface.py
+++ b/saleor/core/taxes/avatax/interface.py
@@ -1,3 +1,4 @@
+import logging
from datetime import date
from decimal import Decimal
from typing import TYPE_CHECKING, List, Union
@@ -11,6 +12,7 @@ from .. import ZERO_TAXED_MONEY, TaxType
from ..errors import TaxError
from . import (
META_FIELD,
+ CustomerErrors,
TransactionType,
api_post_request,
generate_request_data_from_checkout,
@@ -26,6 +28,8 @@ if TYPE_CHECKING:
from ....checkout.models import Checkout
from ....order.models import Order, OrderLine
+logger = logging.getLogger(__name__)
+
def calculate_checkout_total(checkout: "checkout_models.Checkout", discounts):
checkout_total = checkout.get_total(discounts=discounts)
@@ -99,31 +103,29 @@ def preprocess_order_creation(checkout: "Checkout"):
data = generate_request_data_from_checkout(
checkout,
transaction_token=str(checkout.token),
- transaction_type=TransactionType.INVOICE,
+ transaction_type=TransactionType.ORDER,
discounts=discounts,
)
transaction_url = urljoin(get_api_url(), "transactions/createoradjust")
response = api_post_request(transaction_url, data)
- # FIXME errors for users (?)
if not response or "error" in response:
- raise TaxError(response.get("error", {}).get("message", ""))
+ msg = response.get("error", {}).get("message", "")
+ error_code = response.get("error", {}).get("code", "")
+ logger.warning(
+ "Unable to calculate taxes for checkout %s, error_code: %s, error_msg: %s",
+ checkout.token,
+ error_code,
+ msg,
+ )
+ customer_msg = CustomerErrors.get_error_msg(response.get("error", {}))
+ raise TaxError(customer_msg)
def postprocess_order_creation(order: "Order"):
- # FIXME this should be a celery task. it should retry to send an order in case
- # of fail
+ # FIXME after we introduce plugin architecture, this logic could be a celery task
+
+ data = get_order_tax_data(order, commit=False, force_refresh=True)
- # Fixme we can generate data directly from order
- checkout = checkout_models.Checkout.objects.get(token=order.checkout_token)
- discounts = Sale.objects.active(date.today()).prefetch_related(
- "products", "categories", "collections"
- )
- data = generate_request_data_from_checkout(
- checkout,
- transaction_token=str(order.token),
- transaction_type=TransactionType.INVOICE,
- discounts=discounts,
- )
transaction_url = urljoin(get_api_url(), "transactions/createoradjust")
api_post_request(transaction_url, data)
@@ -165,7 +167,7 @@ def calculate_order_line_unit(order_line: "OrderLine"):
def calculate_order_shipping(order: "Order"):
if not validate_order(order):
return ZERO_TAXED_MONEY
- taxes_data = get_order_tax_data(order, None)
+ taxes_data = get_order_tax_data(order, False)
currency = taxes_data.get("currencyCode")
for line in taxes_data.get("lines", []):
if line["itemCode"] == "Shipping":
diff --git a/saleor/core/taxes/interface.py b/saleor/core/taxes/interface.py
index 4ac7b89974..c1d6802ab3 100644
--- a/saleor/core/taxes/interface.py
+++ b/saleor/core/taxes/interface.py
@@ -59,9 +59,9 @@ def calculate_checkout_shipping(
def calculate_order_shipping(order: "Order") -> TaxedMoney:
+ """Calculate shipping price that assigned to order"""
if settings.VATLAYER_ACCESS_KEY:
- # FIXME
- pass
+ return calculate_order_shipping(order)
elif settings.AVATAX_USERNAME_OR_ACCOUNT and settings.AVATAX_PASSWORD_OR_LICENSE:
return avatax_interface.calculate_order_shipping(order)
price = order.shipping_method.price
@@ -85,7 +85,6 @@ def get_tax_rate_type_choices() -> List[TaxType]:
if settings.VATLAYER_ACCESS_KEY:
return vatlayer_interface.get_tax_rate_type_choices()
if settings.AVATAX_USERNAME_OR_ACCOUNT and settings.AVATAX_PASSWORD_OR_LICENSE:
- # FIXME shouldn't use description as a id for tax rates.
return avatax_interface.get_tax_rate_type_choices()
return []
@@ -106,13 +105,7 @@ def calculate_checkout_line_total(
def calculate_order_line_unit(order_line: "OrderLine"):
"""It updates unit_price for a given order line based on current price of variant"""
if settings.VATLAYER_ACCESS_KEY:
- # FIXME Should be inside vatlayer module
- address = order_line.order.shipping_address or order_line.order.billing_address
- country = address.country if address else None
- variant = order_line.variant
- return vatlayer_interface.apply_taxes_to_product(
- variant.product, order_line.unit_price_net, country
- )
+ return vatlayer_interface.calculate_order_line_unit(order_line)
if settings.AVATAX_USERNAME_OR_ACCOUNT and settings.AVATAX_PASSWORD_OR_LICENSE:
return avatax_interface.calculate_order_line_unit(order_line)
return order_line.unit_price
diff --git a/saleor/core/taxes/vatlayer/__init__.py b/saleor/core/taxes/vatlayer/__init__.py
index 2af1ce8147..fc5e8b2f97 100644
--- a/saleor/core/taxes/vatlayer/__init__.py
+++ b/saleor/core/taxes/vatlayer/__init__.py
@@ -1,11 +1,80 @@
from django.conf import settings
+from django.utils.translation import pgettext_lazy
from django_countries.fields import Country
from django_prices_vatlayer.utils import get_tax_for_rate, get_tax_rates_for_country
from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
-from ... import TaxRateType
from .. 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, pgettext_lazy("VAT rate type", "accommodation")),
+ (
+ ADMISSION_TO_CULTURAL_EVENTS,
+ pgettext_lazy("VAT rate type", "admission to cultural events"),
+ ),
+ (
+ ADMISSION_TO_ENTERTAINMENT_EVENTS,
+ pgettext_lazy("VAT rate type", "admission to entertainment events"),
+ ),
+ (
+ ADMISSION_TO_SPORTING_EVENTS,
+ pgettext_lazy("VAT rate type", "admission to sporting events"),
+ ),
+ (ADVERTISING, pgettext_lazy("VAT rate type", "advertising")),
+ (
+ AGRICULTURAL_SUPPLIES,
+ pgettext_lazy("VAT rate type", "agricultural supplies"),
+ ),
+ (BABY_FOODSTUFFS, pgettext_lazy("VAT rate type", "baby foodstuffs")),
+ (BIKES, pgettext_lazy("VAT rate type", "bikes")),
+ (BOOKS, pgettext_lazy("VAT rate type", "books")),
+ (CHILDRENDS_CLOTHING, pgettext_lazy("VAT rate type", "childrens clothing")),
+ (DOMESTIC_FUEL, pgettext_lazy("VAT rate type", "domestic fuel")),
+ (DOMESTIC_SERVICES, pgettext_lazy("VAT rate type", "domestic services")),
+ (E_BOOKS, pgettext_lazy("VAT rate type", "e-books")),
+ (FOODSTUFFS, pgettext_lazy("VAT rate type", "foodstuffs")),
+ (HOTELS, pgettext_lazy("VAT rate type", "hotels")),
+ (MEDICAL, pgettext_lazy("VAT rate type", "medical")),
+ (NEWSPAPERS, pgettext_lazy("VAT rate type", "newspapers")),
+ (PASSENGER_TRANSPORT, pgettext_lazy("VAT rate type", "passenger transport")),
+ (PHARMACEUTICALS, pgettext_lazy("VAT rate type", "pharmaceuticals")),
+ (PROPERTY_RENOVATIONS, pgettext_lazy("VAT rate type", "property renovations")),
+ (RESTAURANTS, pgettext_lazy("VAT rate type", "restaurants")),
+ (SOCIAL_HOUSING, pgettext_lazy("VAT rate type", "social housing")),
+ (STANDARD, pgettext_lazy("VAT rate type", "standard")),
+ (WATER, pgettext_lazy("VAT rate type", "water")),
+ (WINE, pgettext_lazy("VAT rate type", "wine")),
+ )
+
+
DEFAULT_TAX_RATE_NAME = TaxRateType.STANDARD
diff --git a/saleor/core/taxes/vatlayer/interface.py b/saleor/core/taxes/vatlayer/interface.py
index 5be4d06e4c..f9e9b346ad 100644
--- a/saleor/core/taxes/vatlayer/interface.py
+++ b/saleor/core/taxes/vatlayer/interface.py
@@ -4,10 +4,10 @@ from django_countries.fields import Country
from django_prices_vatlayer.utils import get_tax_rate_types
from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
-from ....core import TaxRateType # FIXME this should be placed in VatLayer module
from .. import ZERO_TAXED_MONEY, TaxType
from . import (
DEFAULT_TAX_RATE_NAME,
+ TaxRateType,
apply_tax_to_price,
get_taxed_shipping_price,
get_taxes_for_address,
@@ -19,6 +19,7 @@ if TYPE_CHECKING:
from ....checkout.models import Checkout, CheckoutLine
from ....product.models import Product
from ....account.models import Address
+ from ....order.models import Order, OrderLine
META_FIELD = "vatlayer"
@@ -59,6 +60,21 @@ def calculate_checkout_shipping(checkout: "Checkout", _: "SaleQueryset") -> Taxe
return get_taxed_shipping_price(checkout.shipping_method.price, taxes)
+def calculate_order_shipping(order: "Order") -> TaxedMoney:
+ address = order.shipping_address or order.billing_address
+ taxes = get_taxes_for_address(address)
+ if not order.shipping_method:
+ return ZERO_TAXED_MONEY
+ return get_taxed_shipping_price(order.shipping_method.price, taxes)
+
+
+def calculate_order_line_unit(order_line: "OrderLine") -> TaxedMoney:
+ address = order_line.order.shipping_address or order_line.order.billing_address
+ country = address.country if address else None
+ variant = order_line.variant
+ return apply_taxes_to_product(variant.product, order_line.unit_price_net, country)
+
+
def calculate_checkout_line_total(
checkout_line: "CheckoutLine", discounts: "SaleQueryset"
):
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 119a17e6e0..31ffaf95b2 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -603,7 +603,6 @@ class AddVariantToOrderForm(forms.Form):
def __init__(self, *args, **kwargs):
self.order = kwargs.pop("order")
self.discounts = kwargs.pop("discounts")
- self.taxes = kwargs.pop("taxes") # FIXME
super().__init__(*args, **kwargs)
def clean(self):
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 3e9ba3b3be..fe94e10dc7 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -314,9 +314,8 @@ def orderline_cancel(request, order_pk, line_pk):
def add_variant_to_order(request, order_pk):
"""Add variant in given quantity to an order."""
order = get_object_or_404(Order.objects.drafts(), pk=order_pk)
- taxes = None # FIXME
form = AddVariantToOrderForm(
- request.POST or None, order=order, discounts=request.discounts, taxes=taxes
+ request.POST or None, order=order, discounts=request.discounts
)
status = 200
if form.is_valid():
diff --git a/saleor/dashboard/taxes/views.py b/saleor/dashboard/taxes/views.py
index c61d5637e7..756d36e4e2 100644
--- a/saleor/dashboard/taxes/views.py
+++ b/saleor/dashboard/taxes/views.py
@@ -13,8 +13,7 @@ from django.views.decorators.http import require_POST
from django_countries.fields import Country
from django_prices_vatlayer.models import VAT
-from ...core import TaxRateType
-from ...core.taxes.vatlayer import get_taxes_for_country # FIXME
+from ...core.taxes.vatlayer import TaxRateType, get_taxes_for_country
from ...core.utils import get_paginator_items
from ...dashboard.taxes.filters import TaxFilter
from ...dashboard.taxes.forms import TaxesConfigurationForm
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.py
index 87422fa8ee..e05a4d0291 100644
--- a/saleor/data_feeds/google_merchant.py
+++ b/saleor/data_feeds/google_merchant.py
@@ -125,8 +125,7 @@ def item_tax(item, discounts):
Read more:
https://support.google.com/merchants/answer/6324454
"""
- # FIXME get_price never returns taxed price
- # price = item.get_price(discounts=discounts)
+ # FIXME https://github.com/mirumee/saleor/issues/4311
return "US::%s:y" % ZERO_MONEY
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py
index 36a3be0e7d..7af4636322 100644
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@ -1,10 +1,13 @@
import graphene
-from ...core import TaxRateType as CoreTaxRateType
from ...core.permissions import MODELS_PERMISSIONS
+from ...core.taxes.vatlayer import TaxRateType as CoreTaxRateType
from ...core.weight import WeightUnits
from .utils import str_to_enum
+# FIXME CoreTaxRateType should be removed after we will drop old api fields dedicated
+# to taxes
+
class ReportingPeriod(graphene.Enum):
TODAY = "TODAY"
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 9c9b9be4c8..e2553d870f 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -162,9 +162,11 @@ def update_order_prices(order, discounts):
line.save(update_fields=["unit_price_net", "unit_price_gross"])
price = calculate_order_line_unit(line)
- line.unit_price = price
- line.tax_rate = 0 # Fixme we can calulcate tax_rate based on prices
- line.save()
+ if price != line.unit_price:
+ line.unit_price = price
+ if price.tax and price.net:
+ line.tax_rate = price.tax / price.net
+ line.save()
if order.shipping_method:
order.shipping_price = calculate_order_shipping(order)
diff --git a/saleor/product/models.py b/saleor/product/models.py
index ac447e8beb..5857720c24 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -86,7 +86,6 @@ class ProductType(models.Model):
has_variants = models.BooleanField(default=True)
is_shipping_required = models.BooleanField(default=True)
is_digital = models.BooleanField(default=False)
- # FIXME This should be moved to meta
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES, default=zero_weight
)
@@ -135,7 +134,6 @@ class Product(SeoModel, PublishableModel):
attributes = HStoreField(default=dict, blank=True)
updated_at = models.DateTimeField(auto_now=True, null=True)
charge_taxes = models.BooleanField(default=True)
- # FIXME This should be moved to meta
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES, blank=True, null=True
)
diff --git a/saleor/product/utils/variants_picker.py b/saleor/product/utils/variants_picker.py
index fbf835a580..2bb9477d4b 100644
--- a/saleor/product/utils/variants_picker.py
+++ b/saleor/product/utils/variants_picker.py
@@ -3,12 +3,7 @@ from collections import defaultdict
from django_prices.templatetags import prices_i18n
from ...core.taxes import display_gross_prices
-from ...core.taxes.interface import (
- apply_taxes_to_product,
- get_tax_from_object_meta,
- show_taxes_on_storefront,
-)
-from ...core.taxes.vatlayer import get_tax_rate_by_name
+from ...core.taxes.interface import apply_taxes_to_product, show_taxes_on_storefront
from ...core.utils import to_local_currency
from ...seo.schema.product import variant_json_ld
from .availability import get_product_availability
@@ -75,10 +70,14 @@ def get_variant_picker_data(
}
)
+ product_price = apply_taxes_to_product(product, product.price, country)
+ tax_rates = 0
+ if product_price.tax and product_price.net:
+ tax_rates = int((product_price.tax / product_price.net) * 100)
+
data["availability"] = {
"discount": price_as_dict(availability.discount),
- # FIXME this should use plugin hooks after we will introduce plugin architecure.
- "taxRate": get_tax_rate_by_name(get_tax_from_object_meta(product).code, taxes),
+ "taxRate": tax_rates,
"priceRange": price_range_as_dict(availability.price_range),
"priceRangeUndiscounted": price_range_as_dict(
availability.price_range_undiscounted