Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use discounts and taxes in checkout's total calculations
Marcin Gębala0062e02afbb0
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex b45ad30d43..cea0ea91d6 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -885,14 +885,16 @@ def create_order(cart, tracking_code, discounts, taxes):return order-def is_fully_paid(cart: Cart):+def is_fully_paid(cart: Cart, taxes, discounts):+ """Check if checkout is fully paid."""payments = cart.payments.filter(is_active=True)- total_paid = sum(- [p.total for p in payments])- return total_paid >= cart.get_total().gross.amount+ total_paid = sum([p.total for p in payments])+ cart_total = cart.get_total(discounts=discounts, taxes=taxes).gross.amount+ return total_paid >= cart_totaldef ready_to_place_order(cart: Cart, taxes, discounts):+ """Check if checkout can be completed."""if cart.is_shipping_required():if not cart.shipping_method:return False, pgettext_lazy(@@ -904,7 +906,7 @@ def ready_to_place_order(cart: Cart, taxes, discounts):return False, pgettext_lazy('order placement error','Shipping method is not valid for your shipping address')- if not is_fully_paid(cart):+ if not is_fully_paid(cart, taxes, discounts):return False, pgettext_lazy('order placement error', 'Checkout is not fully paid')return True, Nonediff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex bd5a92eb51..95276db2be 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -28,7 +28,7 @@ class CheckoutLine(CountableDjangoObjectType):def resolve_total_price(self, info):taxes = get_taxes_for_address(self.cart.shipping_address)- return self.get_total(taxes=taxes)+ return self.get_total(discounts=info.context.discounts, taxes=taxes)def resolve_requires_shipping(self, info):return self.is_shipping_required()@@ -73,7 +73,7 @@ class Checkout(CountableDjangoObjectType):def resolve_total_price(self, info):taxes = get_taxes_for_address(self.shipping_address)- return self.get_total(taxes=taxes)+ return self.get_total(discounts=info.context.discounts, taxes=taxes)def resolve_subtotal_price(self, info):taxes = get_taxes_for_address(self.shipping_address)