Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Unify and simplify retrieval of available shipping methods
NyanKiyoshi65852c5a160d
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.pyindex e6404a5495..303f9442bc 100644--- a/saleor/checkout/forms.py+++ b/saleor/checkout/forms.py@@ -12,11 +12,10 @@ from django_countries.fields import Country, LazyTypedChoiceFieldfrom ..core.exceptions import InsufficientStockfrom ..core.taxes import display_gross_prices-from ..core.taxes.interface import apply_taxes_to_shipping, calculate_checkout_subtotal+from ..core.taxes.interface import apply_taxes_to_shippingfrom ..core.utils import format_moneyfrom ..discount.models import NotApplicable, Voucherfrom ..shipping.models import ShippingMethod, ShippingZone-from ..shipping.utils import get_shipping_price_estimatefrom .models import Checkout@@ -200,14 +199,16 @@ class CountryForm(forms.Form):available_countries, key=lambda choice: choice[1])- def get_shipping_price_estimate(self, price, weight):+ def get_shipping_price_estimate(self, checkout, discounts):"""Return a shipping price range for given order for the selectedcountry."""+ from .utils import get_shipping_price_estimate+country = self.cleaned_data["country"]if isinstance(country, str):country = Country(country)- return get_shipping_price_estimate(price, weight, country)+ return get_shipping_price_estimate(checkout, discounts, country)class AnonymousUserShippingForm(forms.ModelForm):@@ -320,14 +321,14 @@ class CheckoutShippingMethodForm(forms.ModelForm):fields = ["shipping_method"]def __init__(self, *args, **kwargs):+ from .utils import get_valid_shipping_methods+discounts = kwargs.pop("discounts")super().__init__(*args, **kwargs)shipping_address = self.instance.shipping_addresscountry_code = shipping_address.country.code- qs = ShippingMethod.objects.applicable_shipping_methods(- price=calculate_checkout_subtotal(self.instance, discounts).gross,- weight=self.instance.get_total_weight(),- country_code=country_code,+ qs = get_valid_shipping_methods(+ self.instance, discounts, country_code=country_code)self.fields["shipping_method"].queryset = qsself.fields["shipping_method"].shipping_address = shipping_addressdiff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex f1aae95292..90596d4b4f 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -11,13 +11,18 @@ from django.db.models import Sumfrom django.utils import timezonefrom django.utils.encoding import smart_textfrom django.utils.translation import get_language, pgettext, pgettext_lazy-from prices import TaxedMoneyRange+from prices import MoneyRange, TaxedMoneyRangefrom ..account.forms import get_address_formfrom ..account.models import Address, Userfrom ..account.utils import store_user_addressfrom ..core.exceptions import InsufficientStock-from ..core.taxes import quantize_price, zero_money, zero_taxed_money+from ..core.taxes import (+ interface as tax_interface,+ quantize_price,+ zero_money,+ zero_taxed_money,+)from ..core.taxes.interface import (calculate_checkout_line_total,calculate_checkout_shipping,@@ -50,7 +55,7 @@ from ..giftcard.utils import (from ..order import eventsfrom ..order.emails import send_order_confirmationfrom ..order.models import Order, OrderLine-from ..shipping.models import ShippingMethod+from ..shipping.utils import applicable_shipping_methodsfrom . import AddressType, loggerfrom .forms import (AddressChoiceForm,@@ -976,22 +981,45 @@ def remove_voucher_from_checkout(checkout: Checkout):)+def get_valid_shipping_methods(checkout: Checkout, discounts, country_code=None):+ return applicable_shipping_methods(+ checkout,+ price=calculate_checkout_subtotal(checkout, discounts).gross.amount,+ 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:return False- valid_methods = ShippingMethod.objects.applicable_shipping_methods(- price=calculate_checkout_subtotal(checkout, discounts).gross,- weight=checkout.get_total_weight(),- country_code=checkout.shipping_address.country.code,- )- if checkout.shipping_method not in valid_methods:+ valid_methods = get_valid_shipping_methods(checkout, discounts)+ if valid_methods is None or checkout.shipping_method not in valid_methods:clear_shipping_method(checkout)return Falsereturn 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(+ checkout, discounts, country_code=country_code+ )++ if shipping_methods is None:+ return++ shipping_methods = shipping_methods.values_list("price", flat=True)++ if not shipping_methods:+ return++ prices = MoneyRange(start=min(shipping_methods), stop=max(shipping_methods))+ return tax_interface.apply_taxes_to_shipping_price_range(prices, country_code)++def clear_shipping_method(checkout):checkout.shipping_method = Nonecheckout.save(update_fields=["shipping_method"])diff --git a/saleor/checkout/views/__init__.py b/saleor/checkout/views/__init__.pyindex 3cdfc250ad..c067ddbdd8 100644--- a/saleor/checkout/views/__init__.py+++ b/saleor/checkout/views/__init__.py@@ -12,13 +12,13 @@ from ...core.taxes import (zero_taxed_money,)from ...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 (check_product_availability_and_warn,get_checkout_context,get_or_empty_db_checkout,+ get_shipping_price_estimate,is_valid_shipping_method,update_checkout_quantity,)@@ -155,9 +155,7 @@ def checkout_index(request, checkout):default_country = get_user_shipping_country(request)country_form = CountryForm(initial={"country": default_country})shipping_price_range = get_shipping_price_estimate(- price=tax_interface.calculate_checkout_subtotal(checkout, discounts).gross,- weight=checkout.get_total_weight(),- country_code=default_country,+ checkout, discounts, country_code=default_country)context = get_checkout_context(@@ -182,10 +180,7 @@ def checkout_shipping_options(request, checkout):country_form = CountryForm(request.POST or None)if country_form.is_valid():shipping_price_range = country_form.get_shipping_price_estimate(- price=tax_interface.calculate_checkout_subtotal(- checkout, request.discounts- ).gross,- weight=checkout.get_total_weight(),+ checkout, request.discounts)else:shipping_price_range = Nonediff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex df25dce0ea..e8b662d032 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -17,6 +17,7 @@ from ...checkout.utils import (clean_checkout,create_order,get_user_checkout,+ get_valid_shipping_methods,get_voucher_for_checkout,prepare_order_data,recalculate_checkout_discount,@@ -27,13 +28,11 @@ from ...checkout.utils import (from ...core import analyticsfrom ...core.exceptions import InsufficientStockfrom ...core.taxes.errors import TaxError-from ...core.taxes.interface import calculate_checkout_subtotalfrom ...discount import models as voucher_modelfrom ...payment import PaymentErrorfrom ...payment.interface import AddressDatafrom ...payment.utils import gateway_process_payment, store_customer_idfrom ...product import models as product_models-from ...shipping.models import ShippingMethod as ShippingMethodModelfrom ..account.i18n import I18nMixinfrom ..account.types import AddressInput, Userfrom ..core.mutations import BaseMutation, ModelMutation@@ -58,14 +57,15 @@ def clean_shipping_method(checkout, method, discounts, country_code=None, remove"shipping address.")- valid_methods = ShippingMethodModel.objects.applicable_shipping_methods(- price=calculate_checkout_subtotal(checkout, discounts).gross.amount,- weight=checkout.get_total_weight(),- country_code=country_code or checkout.shipping_address.country.code,+ valid_methods = get_valid_shipping_methods(+ checkout, discounts, country_code=country_code)- valid_methods = valid_methods.values_list("id", flat=True)- if method.pk not in valid_methods and not remove:+ if (+ valid_methods is None+ or method.pk not in valid_methods.values_list("id", flat=True)+ and not remove+ ):raise ValidationError("Shipping method cannot be used with this checkout.")if remove:@@ -219,9 +219,6 @@ class CheckoutCreate(ModelMutation, I18nMixin):if checkout is not None:# If user has an active checkout, return it without any# modifications.- # FIXME: should we raise an error?- # Nothing was created--which is invalid,- # the user knows nothing about this.return CheckoutCreate(checkout=checkout)checkout = models.Checkout(user=user)diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 7dd16c6263..f08bcac55b 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -3,6 +3,7 @@ import graphene_django_optimizer as gql_optimizerfrom django.conf import settingsfrom ...checkout import models+from ...checkout.utils import get_valid_shipping_methodsfrom ...core.taxes import zero_taxed_moneyfrom ...core.taxes.interface import (calculate_checkout_line_total,@@ -13,7 +14,6 @@ from ...core.taxes.interface import (from ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import TaxedMoneyfrom ..giftcard.types import GiftCard-from ..order.utils import applicable_shipping_methodsfrom ..payment.enums import PaymentGatewayEnumfrom ..shipping.types import ShippingMethod@@ -145,10 +145,10 @@ class Checkout(CountableDjangoObjectType):@staticmethoddef resolve_available_shipping_methods(root: models.Checkout, info):- price = calculate_checkout_subtotal(- checkout=root, discounts=info.context.discounts- )- return applicable_shipping_methods(root, price.gross.amount)+ available = get_valid_shipping_methods(root, info.context.discounts)+ if available is None:+ return []+ return available@staticmethoddef resolve_available_payment_gateways(_: models.Checkout, _info):diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 122b6c8cb8..b00bd4e82c 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -4,7 +4,7 @@ from django.core.exceptions import ValidationErrorfrom ....account.models import Userfrom ....core.taxes import interface as tax_interface, 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, recalculate_orderfrom ....payment import CustomPaymentChoices, PaymentErrorfrom ....payment.utils import (clean_mark_order_as_paid,@@ -13,7 +13,6 @@ from ....payment.utils import (gateway_void,mark_order_as_paid,)-from ....shipping.models import ShippingMethod as ShippingMethodModelfrom ...account.types import AddressInputfrom ...core.mutations import BaseMutationfrom ...core.scalars import Decimal@@ -31,13 +30,10 @@ def clean_order_update_shipping(order, method):})- valid_methods = ShippingMethodModel.objects.applicable_shipping_methods(- price=order.get_subtotal().gross.amount,- weight=order.get_total_weight(),- country_code=order.shipping_address.country.code,- )- valid_methods = valid_methods.values_list("id", flat=True)- if method.pk not in valid_methods:+ valid_methods = get_valid_shipping_methods(order)+ if valid_methods is None or method.pk not in valid_methods.values_list(+ "id", flat=True+ ):raise ValidationError({"shipping_method": "Shipping method cannot be used with this order."})diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex ed9e81e588..b80fb4f1a6 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -5,6 +5,7 @@ from graphene import relayfrom ...order import modelsfrom ...order.models import FulfillmentStatus+from ...order.utils import get_valid_shipping_methodsfrom ...product.templatetags.product_images import get_product_image_thumbnailfrom ..account.types import Userfrom ..core.connection import CountableDjangoObjectType@@ -15,7 +16,7 @@ from ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..product.types import ProductVariantfrom ..shipping.types import ShippingMethodfrom .enums import OrderEventsEmailsEnum, OrderEventsEnum-from .utils import applicable_shipping_methods, validate_draft_order+from .utils import validate_draft_orderclass OrderEventOrderLineObject(graphene.ObjectType):@@ -455,7 +456,10 @@ class Order(CountableDjangoObjectType):@staticmethoddef resolve_available_shipping_methods(root: models.Order, _info):- return applicable_shipping_methods(root, root.get_subtotal().gross.amount)+ available = get_valid_shipping_methods(root)+ if available is None:+ return []+ return available@staticmethoddef resolve_is_shipping_required(root: models.Order, _info):diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex fb28a571e3..d171f7763c 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -1,7 +1,5 @@from django.core.exceptions import ValidationError-from ...shipping import models as shipping_models-def validate_total_quantity(order):if order.get_total_quantity() == 0:@@ -40,18 +38,3 @@ def validate_draft_order(order):validate_shipping_method(order)validate_total_quantity(order)validate_order_lines(order)---# FIXME: is this function needed? QS method might be enough-def applicable_shipping_methods(obj, price):- if not obj.is_shipping_required():- return []- if not obj.shipping_address:- return []-- qs = shipping_models.ShippingMethod.objects- return qs.applicable_shipping_methods(- price=price,- weight=obj.get_total_weight(),- country_code=obj.shipping_address.country.code,- )diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex e031e9db71..18d1e4f354 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -23,6 +23,7 @@ from ..product.utils import (increase_stock,)from ..product.utils.digital_products import get_default_digital_content_settings+from ..shipping.utils import applicable_shipping_methodsfrom . import events@@ -374,3 +375,7 @@ def sum_order_totals(qs):zero = Money(0, currency=settings.DEFAULT_CURRENCY)taxed_zero = TaxedMoney(zero, zero)return sum([order.total for order in qs], taxed_zero)+++def get_valid_shipping_methods(order: Order):+ return applicable_shipping_methods(order, price=order.get_subtotal().gross.amount)diff --git a/saleor/shipping/models.py b/saleor/shipping/models.pyindex e3d8282b93..9dbd7dfea9 100644--- a/saleor/shipping/models.py+++ b/saleor/shipping/models.py@@ -1,6 +1,7 @@from django.conf import settingsfrom django.contrib.postgres.fields import JSONFieldfrom django.db import models+from django.db.models import Qfrom django.utils.safestring import mark_safefrom django.utils.translation import pgettext_lazyfrom django_countries.fields import CountryField@@ -12,14 +13,68 @@ from prices import MoneyRangefrom ..core.utils import format_moneyfrom ..core.utils.json_serializer import CustomJsonEncoderfrom ..core.utils.translations import TranslationProxy-from ..core.weight import WeightUnits, zero_weight-from . import ShippingMethodType-from .utils import (- applicable_price_based_methods,- applicable_weight_based_methods,- get_price_type_display,- get_weight_type_display,+from ..core.weight import (+ WeightUnits,+ convert_weight,+ get_default_weight_unit,+ zero_weight,)+from . import ShippingMethodType+++def _applicable_weight_based_methods(weight, qs):+ """Returns weight based ShippingMethods that can be applied to an order+ with given total weight.+ """+ qs = qs.weight_based()+ min_weight_matched = Q(minimum_order_weight__lte=weight)+ no_weight_limit = Q(maximum_order_weight__isnull=True)+ max_weight_matched = Q(maximum_order_weight__gte=weight)+ return qs.filter(min_weight_matched & (no_weight_limit | max_weight_matched))+++def _applicable_price_based_methods(price, qs):+ """Returns price based ShippingMethods that can be applied to an order+ with given price total.+ """+ qs = qs.price_based()+ min_price_matched = Q(minimum_order_price__lte=price)+ no_price_limit = Q(maximum_order_price__isnull=True)+ max_price_matched = Q(maximum_order_price__gte=price)+ return qs.filter(min_price_matched & (no_price_limit | max_price_matched))+++def _get_price_type_display(min_price, max_price):+ from ..core.utils import format_money++ if max_price is None:+ return pgettext_lazy(+ "Applies to orders more expensive than the min value",+ "%(min_price)s and up",+ ) % {"min_price": format_money(min_price)}+ return pgettext_lazy(+ "Applies to order valued within this price range",+ "%(min_price)s to %(max_price)s",+ ) % {"min_price": format_money(min_price), "max_price": format_money(max_price)}+++def _get_weight_type_display(min_weight, max_weight):+ default_unit = get_default_weight_unit()++ if min_weight.unit != default_unit:+ min_weight = convert_weight(min_weight, default_unit)+ if max_weight and max_weight.unit != default_unit:+ max_weight = convert_weight(max_weight, default_unit)++ if max_weight is None:+ return pgettext_lazy(+ "Applies to orders heavier than the threshold", "%(min_weight)s and up"+ ) % {"min_weight": min_weight}+ return pgettext_lazy(+ "Applies to orders of total weight within this range",+ "%(min_weight)s to %(max_weight)s"+ % {"min_weight": min_weight, "max_weight": max_weight},+ )class ShippingZone(models.Model):@@ -85,8 +140,8 @@ class ShippingMethodQueryset(models.QuerySet):qs = self.filter(shipping_zone__default=True)qs = qs.prefetch_related("shipping_zone").order_by("price")- price_based_methods = applicable_price_based_methods(price, qs)- weight_based_methods = applicable_weight_based_methods(weight, qs)+ price_based_methods = _applicable_price_based_methods(price, qs)+ weight_based_methods = _applicable_weight_based_methods(weight, qs)return price_based_methods | weight_based_methods@@ -157,7 +212,7 @@ class ShippingMethod(models.Model):)return "ShippingMethod(type=%s weight_range=(%s)" % (self.type,- get_weight_type_display(+ _get_weight_type_display(self.minimum_order_weight, self.maximum_order_weight),)@@ -172,10 +227,10 @@ class ShippingMethod(models.Model):def get_type_display(self):if self.type == ShippingMethodType.PRICE_BASED:- return get_price_type_display(+ return _get_price_type_display(self.minimum_order_price, self.maximum_order_price)- return get_weight_type_display(+ return _get_weight_type_display(self.minimum_order_weight, self.maximum_order_weight)diff --git a/saleor/shipping/utils.py b/saleor/shipping/utils.pyindex 73c1992918..d84ff4cf8c 100644--- a/saleor/shipping/utils.py+++ b/saleor/shipping/utils.py@@ -1,75 +1,23 @@-from django.db.models import Q-from django.utils.translation import pgettext_lazy-from prices import MoneyRange+from typing import TYPE_CHECKING, Union-from ..core.taxes import interface as tax_interface-from ..core.weight import convert_weight, get_default_weight_unit+from .models import ShippingMethod+if TYPE_CHECKING:+ from ..checkout.models import Checkout # noqa: F401+ from ..order.models import Order # noqa: F401-def get_shipping_price_estimate(price, weight, country_code):- """Returns estimated price range for shipping for given order."""- from .models import ShippingMethod- shipping_methods = ShippingMethod.objects.applicable_shipping_methods(- price, weight, country_code- )- shipping_methods = shipping_methods.values_list("price", flat=True)- if not shipping_methods:- return- prices = MoneyRange(start=min(shipping_methods), stop=max(shipping_methods))- return tax_interface.apply_taxes_to_shipping_price_range(prices, country_code)---def applicable_weight_based_methods(weight, qs):- """Returns weight based ShippingMethods that can be applied to an order- with given total weight.- """- qs = qs.weight_based()- min_weight_matched = Q(minimum_order_weight__lte=weight)- no_weight_limit = Q(maximum_order_weight__isnull=True)- max_weight_matched = Q(maximum_order_weight__gte=weight)- return qs.filter(min_weight_matched & (no_weight_limit | max_weight_matched))---def applicable_price_based_methods(price, qs):- """Returns price based ShippingMethods that can be applied to an order- with given price total.- """- qs = qs.price_based()- min_price_matched = Q(minimum_order_price__lte=price)- no_price_limit = Q(maximum_order_price__isnull=True)- max_price_matched = Q(maximum_order_price__gte=price)- return qs.filter(min_price_matched & (no_price_limit | max_price_matched))---def get_price_type_display(min_price, max_price):- from ..core.utils import format_money-- if max_price is None:- return pgettext_lazy(- "Applies to orders more expensive than the min value",- "%(min_price)s and up",- ) % {"min_price": format_money(min_price)}- return pgettext_lazy(- "Applies to order valued within this price range",- "%(min_price)s to %(max_price)s",- ) % {"min_price": format_money(min_price), "max_price": format_money(max_price)}---def get_weight_type_display(min_weight, max_weight):- default_unit = get_default_weight_unit()-- if min_weight.unit != default_unit:- min_weight = convert_weight(min_weight, default_unit)- if max_weight and max_weight.unit != default_unit:- max_weight = convert_weight(max_weight, default_unit)+def applicable_shipping_methods(+ instance: Union["Checkout", "Order"], price, country_code=None+):+ if not instance.is_shipping_required():+ return None+ if not instance.shipping_address:+ return None- if max_weight is None:- return pgettext_lazy(- "Applies to orders heavier than the threshold", "%(min_weight)s and up"- ) % {"min_weight": min_weight}- return pgettext_lazy(- "Applies to orders of total weight within this range",- "%(min_weight)s to %(max_weight)s"- % {"min_weight": min_weight, "max_weight": max_weight},+ qs = ShippingMethod.objects+ return qs.applicable_shipping_methods(+ price=price,+ weight=instance.get_total_weight(),+ country_code=country_code or instance.shipping_address.country.code,)diff --git a/tests/test_cart.py b/tests/test_cart.pyindex 8f3d7095eb..8f71d973bc 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -16,12 +16,12 @@ from saleor.checkout.utils import (add_variant_to_checkout,change_checkout_user,find_open_checkout_for_user,+ get_shipping_price_estimate,)from saleor.checkout.views import clear_checkout, update_checkout_linefrom saleor.core.exceptions import InsufficientStockfrom saleor.discount.models import Salefrom saleor.product.models import Category-from saleor.shipping.utils import get_shipping_price_estimate@pytest.fixture()@@ -722,14 +722,16 @@ def test_update_checkout_line_qunatity_zero(assert data == expected_response-def test_get_checkout_context(checkout_with_single_item, shipping_zone):+def test_get_checkout_context(checkout_with_single_item, shipping_zone, address):+ checkout = checkout_with_single_item+ checkout.shipping_address = address+ checkout.save(update_fields=["shipping_address"])+shipment_option = get_shipping_price_estimate(- checkout_with_single_item.get_subtotal(),- checkout_with_single_item.get_total_weight(),- "PL",+ checkout, discounts=None, country_code="PL")checkout_data = utils.get_checkout_context(- checkout_with_single_item, None, currency="USD", shipping_range=shipment_option+ checkout, None, currency="USD", shipping_range=shipment_option)assert checkout_data["checkout_total"] == TaxedMoney(net=Money("10.00", "USD"), gross=Money("10.00", "USD")@@ -739,14 +741,16 @@ def test_get_checkout_context(checkout_with_single_item, shipping_zone):)-def test_get_checkout_context_no_shipping(checkout_with_single_item):+def test_get_checkout_context_no_shipping(checkout_with_single_item, address):+ checkout = checkout_with_single_item+ checkout.shipping_address = address+ checkout.save(update_fields=["shipping_address"])+shipment_option = get_shipping_price_estimate(- checkout_with_single_item.get_subtotal(),- checkout_with_single_item.get_total_weight(),- "PL",+ checkout, discounts=None, country_code="PL")checkout_data = utils.get_checkout_context(- checkout_with_single_item, None, currency="USD", shipping_range=shipment_option+ checkout, None, currency="USD", shipping_range=shipment_option)checkout_total = checkout_data["checkout_total"]assert checkout_total == TaxedMoney(