Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge branch 'master' into enable_extension_manager_for_taxes
Maciej Korycinski7dfacd0055ea
diff --cc CHANGELOG.mdindex c5273257a6,b46261b9de..f9ac693551--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -9,11 -9,16 +9,19 @@@ All notable, unreleased changes to thi- Fix time zone based tests - #4468 by @fowczarek- Move Django Debug Toolbar requirement to the "dev" one (also downgrade it 2.0 -> 1.11, see PR) - #4454 by @derenio- Add voucher once per customer - #4442 by @fowczarek+ - Fix voucher limit value when checkbox unchecked - #4456 by @benekex2+ - New menu design - #4476 by @benekex2+ - Mutation for changing logged user first and last name - #4489 by @fowczarek+ - Add mutation for deleting account - #4494 by @fowczarek- New translations:- Greek+- Extensions Manager - #4497 by @korycins+- Migration of tax logic into a plugin architecture - #4497 by @korycins++ - Fix searches and pickers - #4487 by @dominik-zeglen+ - Fix dashboard menu styles - #4491 by @benekex2+ - Do not allow random ids to appear in snapshots - #4495 by @dominik-zeglen+ - Order is no longer created when the payment was unsuccessful in the API - #4500 by @NyanKiyoshi## 2.8.0diff --cc saleor/checkout/forms.pyindex 4e86f992c1,65fb70ea02..0a06d4b696--- a/saleor/checkout/forms.py+++ b/saleor/checkout/forms.py@@@ -321,8 -321,9 +322,10 @@@ class CheckoutShippingMethodForm(forms.fields = ["shipping_method"]def __init__(self, *args, **kwargs):+ from .utils import get_valid_shipping_methods_for_checkout+discounts = kwargs.pop("discounts")+ extensions = get_extensions_manager()super().__init__(*args, **kwargs)shipping_address = self.instance.shipping_addresscountry_code = shipping_address.country.codediff --cc saleor/checkout/utils.pyindex dff1b26823,a4d2f6bee7..275cd890b2--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@@ -956,6 -972,16 +974,17 @@@ def remove_voucher_from_checkout(checko)+ def get_valid_shipping_methods_for_checkout(+ checkout: Checkout, discounts, country_code=None+ ):++ manager = get_extensions_manager()+ return ShippingMethod.objects.applicable_shipping_methods_for_instance(+ checkout,- price=calculate_checkout_subtotal(checkout, discounts).gross,++ price=manager.calculate_checkout_subtotal(checkout, discounts).gross,+ country_code=country_code,+ )++def is_valid_shipping_method(checkout, discounts):"""Check if shipping method is valid and remove (if not)."""if not checkout.shipping_method:@@@ -973,6 -994,25 +997,26 @@@return True+ def get_shipping_price_estimate(checkout: Checkout, discounts, country_code):+ """Returns estimated price range for shipping for given order."""++ shipping_methods = get_valid_shipping_methods_for_checkout(+ checkout, discounts, country_code=country_code+ )++ if shipping_methods is None:+ return None++ shipping_methods = shipping_methods.values_list("price", flat=True)++ if not shipping_methods:+ return None+++ manager = get_extensions_manager()+ prices = MoneyRange(start=min(shipping_methods), stop=max(shipping_methods))- return tax_interface.apply_taxes_to_shipping_price_range(prices, country_code)++ return manager.apply_taxes_to_shipping_price_range(prices, country_code)++def clear_shipping_method(checkout):checkout.shipping_method = Nonecheckout.save(update_fields=["shipping_method"])diff --cc saleor/checkout/views/__init__.pyindex 1862adf128,c067ddbdd8..9583c13fd8--- a/saleor/checkout/views/__init__.py+++ b/saleor/checkout/views/__init__.py@@@ -5,9 -5,13 +5,8 @@@ from django.shortcuts import get_objectfrom django.template.response import TemplateResponsefrom ...account.forms import LoginForm-from ...core.taxes import (- get_display_price,- interface as tax_interface,- quantize_price,- zero_taxed_money,-)+from ...core.taxes import get_display_price, quantize_price, zero_taxed_moneyfrom ...core.utils import format_money, get_user_shipping_country, to_local_currency- from ...shipping.utils import get_shipping_price_estimatefrom ..forms import CheckoutShippingMethodForm, CountryForm, ReplaceCheckoutLineFormfrom ..models import Checkoutfrom ..utils import (diff --cc saleor/graphql/checkout/mutations.pyindex 1b9fcec20c,611a507ca0..060ec0d147--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@@ -23,8 -26,7 +26,7 @@@ from ...checkout.utils import)from ...core import analyticsfrom ...core.exceptions import InsufficientStock- from ...core.extensions.manager import get_extensions_manager-from ...core.taxes.errors import TaxError+from ...core.taxes import TaxErrorfrom ...discount import models as voucher_modelfrom ...payment import PaymentErrorfrom ...payment.interface import AddressDatadiff --cc saleor/graphql/checkout/types.pyindex 9d4fdc3001,fda94a8b7e..67ffea8ab0--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@@ -3,7 -3,14 +3,8 @@@ import graphene_django_optimizer as gqlfrom django.conf import settingsfrom ...checkout import models+ from ...checkout.utils import get_valid_shipping_methods_for_checkoutfrom ...core.taxes import zero_taxed_money-from ...core.taxes.interface import (- calculate_checkout_line_total,- calculate_checkout_shipping,- calculate_checkout_subtotal,- calculate_checkout_total,-)from ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import TaxedMoneyfrom ..giftcard.types import GiftCarddiff --cc saleor/graphql/order/mutations/orders.pyindex a856029319,6779ae78d2..8cbf7ed55f--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@@ -2,9 -2,13 +2,13 @@@ import graphenfrom django.core.exceptions import ValidationErrorfrom ....account.models import User-from ....core.taxes import interface as tax_interface, zero_taxed_money+from ....core.taxes import zero_taxed_moneyfrom ....order import events, models- from ....order.utils import cancel_order, recalculate_order+ from ....order.utils import (+ cancel_order,+ get_valid_shipping_methods_for_order,+ recalculate_order,+ )from ....payment import CustomPaymentChoices, PaymentErrorfrom ....payment.utils import (clean_mark_order_as_paid,diff --cc saleor/graphql/product/types/products.pyindex a7684cc65d,c353c67f54..f29703bf23--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@@ -450,16 -452,14 +450,16 @@@ class Product(CountableDjangoObjectType]@staticmethod- def resolve_tax_rate(root: models.ProductType, info, **_kwargs):+ def resolve_tax_rate(root: models.Product, _info, **_kwargs):# FIXME this resolver should be dropped after we drop tax_rate from API- tax_rate = vatlayer_interface.get_tax_from_object_meta(root).code- return tax_rate or None+ if not hasattr(root, "meta"):+ return None+ tax = root.meta.get("taxes", {}).get("vatlayer", {})+ return tax.get("code")@staticmethod- def resolve_tax_type(root: models.Product, _info):- tax_data = tax_interface.get_tax_from_object_meta(root)+ def resolve_tax_type(root: models.Product, info):+ tax_data = info.context.extensions.get_tax_code_from_object_meta(root)return TaxType(tax_code=tax_data.code, description=tax_data.description)@staticmethoddiff --cc tests/settings.pyindex b4c8d0898f,9d29313a48..245f7fdff3--- a/tests/settings.py+++ b/tests/settings.py@@@ -39,7 -39,6 +39,7 @@@ COUNTRIES_ONLY = NonMEDIA_ROOT = NoneMAX_CHECKOUT_LINE_QUANTITY = 50++USE_JSON_CONTENT = FalsePASSWORD_HASHERS = ["tests.dummy_password_hasher.DummyHasher"]--USE_JSON_CONTENT = False+EXTENSIONS_MANAGER = "saleor.core.extensions.manager.ExtensionsManager"