Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move quantize method to calculations
Damian W5d5fbd9df95a
diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.pyindex 4273c20c83..79bae61ce6 100644--- a/saleor/checkout/calculations.py+++ b/saleor/checkout/calculations.py@@ -1,5 +1,6 @@from typing import TYPE_CHECKING, Iterable, Optional+from ..core.taxes import quantize_pricefrom ..discount import DiscountInfofrom ..plugins.manager import get_plugins_manager@@ -18,9 +19,10 @@ def checkout_shipping_price(It takes in account all plugins."""- return get_plugins_manager().calculate_checkout_shipping(+ calculated_checkout_shipping = get_plugins_manager().calculate_checkout_shipping(checkout, lines, discounts or [])+ return quantize_price(calculated_checkout_shipping, checkout.currency)def checkout_subtotal(@@ -33,9 +35,10 @@ def checkout_subtotal(It takes in account all plugins."""- return get_plugins_manager().calculate_checkout_subtotal(+ calculated_checkout_subtotal = get_plugins_manager().calculate_checkout_subtotal(checkout, lines, discounts or [])+ return quantize_price(calculated_checkout_subtotal, checkout.currency)def checkout_total(@@ -51,9 +54,10 @@ def checkout_total(It takes in account all plugins."""- return get_plugins_manager().calculate_checkout_total(+ calculated_checkout_total = get_plugins_manager().calculate_checkout_total(checkout, lines, discounts or [])+ return quantize_price(calculated_checkout_total, checkout.currency)def checkout_line_total(@@ -63,4 +67,7 @@ def checkout_line_total(It takes in account all plugins."""- return get_plugins_manager().calculate_checkout_line_total(line, discounts or [])+ calculated_line_total = get_plugins_manager().calculate_checkout_line_total(+ line, discounts or []+ )+ return quantize_price(calculated_line_total, line.checkout.currency)diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 086a26188c..19d1d71a22 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -2,6 +2,7 @@ import graphenefrom django.conf import settingsfrom django.core.exceptions import ValidationError+from ...checkout import calculationsfrom ...core.permissions import OrderPermissionsfrom ...core.taxes import zero_taxed_moneyfrom ...core.utils import get_client_ip@@ -69,11 +70,14 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):@classmethoddef calculate_total(cls, info, checkout):checkout_total = (- info.context.plugins.calculate_checkout_total(- checkout, lines=list(checkout), discounts=info.context.discounts+ calculations.checkout_total(+ checkout=checkout,+ lines=list(checkout),+ discounts=info.context.discounts,)- checkout.get_total_gift_cards_balance())+return max(checkout_total, zero_taxed_money(checkout_total.currency))@classmethoddiff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.pyindex 29828d1553..09505b1110 100644--- a/saleor/plugins/avatax/plugin.py+++ b/saleor/plugins/avatax/plugin.py@@ -139,9 +139,7 @@ class AvataxPlugin(BasePlugin):voucher_value = checkout.discountif voucher_value:total -= voucher_value- return quantize_price(- max(total, zero_taxed_money(total.currency)), total.currency- )+ return max(total, zero_taxed_money(total.currency))def _calculate_checkout_subtotal(self, currency: str, lines: List[Dict]@@ -156,9 +154,7 @@ class AvataxPlugin(BasePlugin):sub_total_gross = Money(sub_net + sub_tax, currency)sub_total_net = Money(sub_net, currency)- return quantize_price(- TaxedMoney(net=sub_total_net, gross=sub_total_gross), currency- )+ return TaxedMoney(net=sub_total_net, gross=sub_total_gross)def calculate_checkout_subtotal(self,@@ -194,9 +190,7 @@ class AvataxPlugin(BasePlugin):shipping_gross = Money(amount=shipping_net + shipping_tax, currency=currency)shipping_net = Money(amount=shipping_net, currency=currency)- return quantize_price(- TaxedMoney(net=shipping_net, gross=shipping_gross), currency- )+ return TaxedMoney(net=shipping_net, gross=shipping_gross)def calculate_checkout_shipping(self,diff --git a/tests/plugins/test_avatax.py b/tests/plugins/test_avatax.pyindex 16a336a3db..6a04bf5130 100644--- a/tests/plugins/test_avatax.py+++ b/tests/plugins/test_avatax.py@@ -169,6 +169,7 @@ def test_calculate_checkout_shipping(shipping_price = manager.calculate_checkout_shipping(checkout_with_item, list(checkout_with_item), [discount_info])+ shipping_price = quantize_price(shipping_price, shipping_price.currency)assert shipping_price == TaxedMoney(net=Money("8.13", "USD"), gross=Money("10.00", "USD"))