Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Rename functions in tax_interface
Maciej Korycinski08bc321e51b2
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.pyindex 7de257e83a..772d23c8c6 100644--- a/saleor/checkout/forms.py+++ b/saleor/checkout/forms.py@@ -12,7 +12,7 @@ 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, get_subtotal_gross+from ..core.taxes.interface import apply_taxes_to_shipping, calculate_checkout_subtotalfrom ..core.utils import format_moneyfrom ..discount.models import NotApplicable, Voucherfrom ..shipping.models import ShippingMethod, ShippingZone@@ -324,7 +324,7 @@ class CheckoutShippingMethodForm(forms.ModelForm):shipping_address = self.instance.shipping_addresscountry_code = shipping_address.country.codeqs = ShippingMethod.objects.applicable_shipping_methods(- price=get_subtotal_gross(self.instance, discounts).gross,+ price=calculate_checkout_subtotal(self.instance, discounts).gross,weight=self.instance.get_total_weight(),country_code=country_code,)diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex e47171a107..d09c8df391 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -17,11 +17,11 @@ from ..account.utils import store_user_addressfrom ..core.exceptions import InsufficientStockfrom ..core.taxes import ZERO_MONEY, ZERO_TAXED_MONEYfrom ..core.taxes.interface import (+ calculate_checkout_line_total,+ calculate_checkout_shipping,+ calculate_checkout_subtotal,+ calculate_checkout_total,checkout_are_taxes_handled,- get_line_total_gross,- get_shipping_gross,- get_subtotal_gross,- get_total_gross,postprocess_order_creation,preprocess_order_creation,)@@ -654,12 +654,12 @@ def change_shipping_address_in_checkout(checkout, address):def get_checkout_context(checkout, discounts, currency=None, shipping_range=None):"""Data shared between views in checkout process."""checkout_total = (- get_total_gross(checkout=checkout, discounts=discounts)+ calculate_checkout_total(checkout=checkout, discounts=discounts)- checkout.get_total_gift_cards_balance())checkout_total = max(checkout_total, ZERO_TAXED_MONEY)- checkout_subtotal = get_subtotal_gross(checkout, discounts)- shipping_price = get_shipping_gross(checkout, discounts)+ checkout_subtotal = calculate_checkout_subtotal(checkout, discounts)+ shipping_price = calculate_checkout_shipping(checkout, discounts)shipping_required = checkout.is_shipping_required()total_with_shipping = TaxedMoneyRange(@@ -672,7 +672,7 @@ def get_checkout_context(checkout, discounts, currency=None, shipping_range=None"checkout": checkout,"checkout_are_taxes_handled": checkout_are_taxes_handled(),"checkout_lines": [- (line, get_line_total_gross(line, discounts)) for line in checkout+ (line, calculate_checkout_line_total(line, discounts)) for line in checkout],"checkout_shipping_price": shipping_price,"checkout_subtotal": checkout_subtotal,@@ -787,7 +787,7 @@ def recalculate_checkout_discount(checkout, discounts):except NotApplicable:remove_voucher_from_checkout(checkout)else:- subtotal = get_subtotal_gross(checkout, discounts).gross+ subtotal = calculate_checkout_subtotal(checkout, discounts).grosscheckout.discount_amount = min(discount, subtotal)checkout.discount_name = str(voucher)checkout.translated_discount_name = (@@ -895,7 +895,7 @@ def is_valid_shipping_method(checkout, discounts):return Falsevalid_methods = ShippingMethod.objects.applicable_shipping_methods(- price=get_subtotal_gross(checkout, discounts).gross,+ price=calculate_checkout_subtotal(checkout, discounts).gross,weight=checkout.get_total_weight(),country_code=checkout.shipping_address.country.code,)@@ -1005,7 +1005,7 @@ def create_line_for_order(checkout_line: CheckoutLine, discounts) -> OrderLine:if translated_product_name == product_name:translated_product_name = ""- total_line_price = get_line_total_gross(checkout_line, discounts)+ total_line_price = calculate_checkout_line_total(checkout_line, discounts)unit_price = total_line_price / checkout_line.quantityline = OrderLine(product_name=product_name,@@ -1030,12 +1030,12 @@ def prepare_order_data(*, checkout: Checkout, tracking_code: str, discounts) ->order_data = {}total = (- get_total_gross(checkout=checkout, discounts=discounts)+ calculate_checkout_total(checkout=checkout, discounts=discounts)- checkout.get_total_gift_cards_balance())total = max(total, ZERO_TAXED_MONEY)- shipping_total = get_shipping_gross(checkout, discounts)+ shipping_total = calculate_checkout_shipping(checkout, discounts)order_data.update(_process_shipping_data_for_order(checkout, shipping_total))order_data.update(_process_user_data_for_order(checkout))order_data.update(@@ -1059,7 +1059,7 @@ def prepare_order_data(*, checkout: Checkout, tracking_code: str, discounts) -># assign gift cards to the orderorder_data["total_price_left"] = (- get_subtotal_gross(checkout, discounts)+ calculate_checkout_subtotal(checkout, discounts)+ shipping_total- checkout.discount_amount).gross@@ -1128,7 +1128,7 @@ def is_fully_paid(checkout: Checkout, discounts):payments = [payment for payment in checkout.payments.all() if payment.is_active]total_paid = sum([p.total for p in payments])checkout_total = (- get_total_gross(checkout=checkout, discounts=discounts)+ calculate_checkout_total(checkout=checkout, discounts=discounts)- checkout.get_total_gift_cards_balance())checkout_total = max(checkout_total, ZERO_TAXED_MONEY).grossdiff --git a/saleor/checkout/views/__init__.py b/saleor/checkout/views/__init__.pyindex 0c6faa7509..fdccd89a8e 100644--- a/saleor/checkout/views/__init__.py+++ b/saleor/checkout/views/__init__.py@@ -139,7 +139,7 @@ def checkout_index(request, checkout):initial=initial,discounts=discounts,)- total_line = tax_interface.get_line_total_gross(line, discounts)+ total_line = tax_interface.calculate_checkout_line_total(line, discounts)variant_price = total_line / line.quantitycheckout_lines.append({@@ -153,7 +153,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.get_subtotal_gross(checkout, discounts).gross,+ price=tax_interface.calculate_checkout_subtotal(checkout, discounts).gross,weight=checkout.get_total_weight(),country_code=default_country,)@@ -180,7 +180,9 @@ 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.get_subtotal_gross(checkout, request.discounts).gross,+ price=tax_interface.calculate_checkout_subtotal(+ checkout, request.discounts+ ).gross,weight=checkout.get_total_weight(),)else:@@ -218,7 +220,9 @@ def update_checkout_line(request, checkout, variant_id):checkout_line = checkout.lines.filter(variant_id=variant_id).first()line_total = ZERO_TAXED_MONEYif checkout_line:- line_total = tax_interface.get_line_total_gross(checkout_line, discounts)+ line_total = tax_interface.calculate_checkout_line_total(+ checkout_line, discounts+ )subtotal = get_display_price(line_total)response = {"variantId": variant_id,@@ -227,7 +231,7 @@ def update_checkout_line(request, checkout, variant_id):"checkout": {"numItems": checkout.quantity, "numLines": len(checkout)},}- checkout_total = tax_interface.get_subtotal_gross(checkout, discounts)+ checkout_total = tax_interface.calculate_checkout_subtotal(checkout, discounts)checkout_total = get_display_price(checkout_total)response["total"] = format_money(checkout_total)local_checkout_total = to_local_currency(checkout_total, request.currency)@@ -266,7 +270,7 @@ def checkout_dropdown(request, checkout):"variant": line.variant,"quantity": line.quantity,"image": first_image,- "line_total": tax_interface.get_line_total_gross(line, discounts),+ "line_total": tax_interface.calculate_checkout_line_total(line, discounts),"variant_url": line.variant.get_absolute_url(),}@@ -275,7 +279,7 @@ def checkout_dropdown(request, checkout):else:data = {"quantity": checkout.quantity,- "total": tax_interface.get_subtotal_gross(checkout, discounts),+ "total": tax_interface.calculate_checkout_subtotal(checkout, discounts),"lines": [prepare_line_data(line) for line in checkout],}diff --git a/saleor/core/taxes/interface.py b/saleor/core/taxes/interface.pyindex 495c7d73a8..c9b6b9f524 100644--- a/saleor/core/taxes/interface.py+++ b/saleor/core/taxes/interface.py@@ -16,7 +16,9 @@ if TYPE_CHECKING:from ...order.models import OrderLine, Order-def get_total_gross(checkout: "Checkout", discounts: "SaleQueryset") -> TaxedMoney:+def calculate_checkout_total(+ checkout: "Checkout", discounts: "SaleQueryset"+) -> TaxedMoney:"""Calculate total gross for checkout"""if settings.VATLAYER_ACCESS_KEY:@@ -28,7 +30,9 @@ def get_total_gross(checkout: "Checkout", discounts: "SaleQueryset") -> TaxedMonreturn TaxedMoney(net=total, gross=total)-def get_subtotal_gross(checkout: "Checkout", discounts: "SaleQueryset") -> TaxedMoney:+def calculate_checkout_subtotal(+ checkout: "Checkout", discounts: "SaleQueryset"+) -> TaxedMoney:"""Calculate subtotal gross for checkout"""if settings.VATLAYER_ACCESS_KEY:@@ -40,7 +44,9 @@ def get_subtotal_gross(checkout: "Checkout", discounts: "SaleQueryset") -> Taxedreturn TaxedMoney(net=subtotal, gross=subtotal)-def get_shipping_gross(checkout: "Checkout", discounts: "SaleQueryset") -> TaxedMoney:+def calculate_checkout_shipping(+ checkout: "Checkout", discounts: "SaleQueryset"+) -> TaxedMoney:"""Calculate shipping gross for checkout"""if not checkout.shipping_method:return ZERO_TAXED_MONEY@@ -84,7 +90,9 @@ def get_tax_rate_type_choices() -> List[TaxType]:return []-def get_line_total_gross(checkout_line: "CheckoutLine", discounts: "SaleQueryset"):+def calculate_checkout_line_total(+ checkout_line: "CheckoutLine", discounts: "SaleQueryset"+):if settings.VATLAYER_ACCESS_KEY:return vatlayer_interface.get_line_total_gross(checkout_line, discounts)if settings.AVATAX_USERNAME_OR_ACCOUNT and settings.AVATAX_PASSWORD_OR_LICENSE:diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex de5b81803b..3e69abc286 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -25,7 +25,7 @@ from ...checkout.utils import (from ...core import analyticsfrom ...core.exceptions import InsufficientStockfrom ...core.taxes.errors import TaxError-from ...core.taxes.interface import get_subtotal_gross+from ...core.taxes.interface import calculate_checkout_subtotalfrom ...discount import models as voucher_modelfrom ...payment import PaymentErrorfrom ...payment.interface import AddressData@@ -56,7 +56,7 @@ def clean_shipping_method(checkout, method, discounts, country_code=None, remove)valid_methods = ShippingMethodModel.objects.applicable_shipping_methods(- price=get_subtotal_gross(checkout, discounts).gross.amount,+ price=calculate_checkout_subtotal(checkout, discounts).gross.amount,weight=checkout.get_total_weight(),country_code=country_code or checkout.shipping_address.country.code,)diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 02a399ab61..fbb1572ecc 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -5,10 +5,10 @@ from django.conf import settingsfrom ...checkout import modelsfrom ...core.taxes import ZERO_TAXED_MONEYfrom ...core.taxes.interface import (- get_line_total_gross,- get_shipping_gross,- get_subtotal_gross,- get_total_gross,+ calculate_checkout_line_total,+ calculate_checkout_shipping,+ calculate_checkout_subtotal,+ calculate_checkout_total,)from ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import TaxedMoney@@ -36,7 +36,7 @@ class CheckoutLine(CountableDjangoObjectType):@staticmethoddef resolve_total_price(self, info):- return get_line_total_gross(+ return calculate_checkout_line_total(checkout_line=self, discounts=info.context.discounts)@@ -118,18 +118,22 @@ class Checkout(CountableDjangoObjectType):@staticmethoddef resolve_total_price(root: models.Checkout, info):taxed_total = (- get_total_gross(checkout=root, discounts=info.context.discounts)+ calculate_checkout_total(checkout=root, discounts=info.context.discounts)- root.get_total_gift_cards_balance())return max(taxed_total, ZERO_TAXED_MONEY)@staticmethoddef resolve_subtotal_price(root: models.Checkout, info):- return get_subtotal_gross(checkout=root, discounts=info.context.discounts)+ return calculate_checkout_subtotal(+ checkout=root, discounts=info.context.discounts+ )@staticmethoddef resolve_shipping_price(root: models.Checkout, info):- return get_shipping_gross(checkout=root, discounts=info.context.discounts)+ return calculate_checkout_shipping(+ checkout=root, discounts=info.context.discounts+ )@staticmethoddef resolve_lines(root: models.Checkout, *_args):@@ -137,7 +141,9 @@ class Checkout(CountableDjangoObjectType):@staticmethoddef resolve_available_shipping_methods(root: models.Checkout, info):- price = get_subtotal_gross(checkout=root, discounts=info.context.discounts)+ price = calculate_checkout_subtotal(+ checkout=root, discounts=info.context.discounts+ )return applicable_shipping_methods(root, price.gross.amount)@staticmethoddiff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 328b34007b..8f01d9902a 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -3,7 +3,7 @@ from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom ...core.taxes import ZERO_TAXED_MONEY-from ...core.taxes.interface import get_total_gross+from ...core.taxes.interface import calculate_checkout_totalfrom ...core.utils import get_client_ipfrom ...payment import PaymentError, modelsfrom ...payment.utils import (@@ -80,7 +80,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):{"billing_address": "No billing address associated with this checkout."})checkout_total = (- get_total_gross(checkout, discounts=info.context.discounts)+ calculate_checkout_total(checkout, discounts=info.context.discounts)- checkout.get_total_gift_cards_balance())checkout_total = max(checkout_total, ZERO_TAXED_MONEY)