Rename get_cart_total

This commit is contained in:
Raphael Michel
2025-08-11 16:43:48 +02:00
parent 3735b6b5a9
commit e30e738e96
4 changed files with 22 additions and 10 deletions

View File

@@ -71,7 +71,7 @@ from pretix.helpers.countries import CachedCountries
from pretix.helpers.format import format_map
from pretix.helpers.money import DecimalTextInput
from pretix.multidomain.urlreverse import build_absolute_uri
from pretix.presale.views import get_cart, get_cart_total
from pretix.presale.views import get_cart, get_cart_position_sum
from pretix.presale.views.cart import cart_session, get_or_create_cart_id
logger = logging.getLogger(__name__)
@@ -1147,7 +1147,7 @@ class FreeOrderProvider(BasePaymentProvider):
from .services.cart import get_fees
cart = get_cart(request)
total = get_cart_total(request)
total = get_cart_position_sum(request)
try:
total += sum([f.value for f in get_fees(self.event, request, total, None, None, cart)])
except TaxRule.SaleNotAllowed:

View File

@@ -73,7 +73,7 @@ from pretix.plugins.paypal2.payment import (
PaypalMethod, PaypalMethod as Paypal, PaypalWallet,
)
from pretix.plugins.paypal.models import ReferencedPayPalObject
from pretix.presale.views import get_cart, get_cart_total
from pretix.presale.views import get_cart, get_cart_position_sum
from pretix.presale.views.cart import cart_session
logger = logging.getLogger('pretix.plugins.paypal2')
@@ -147,7 +147,7 @@ class XHRView(View):
cart_total = order.pending_sum + fee
else:
cart_total = get_cart_total(request)
cart_total = get_cart_position_sum(request)
cart_payments = cart_session(request).get('payments', [])
multi_use_cart_payments = [p for p in cart_payments if p.get('multi_use_supported')]
simulated_payments = multi_use_cart_payments + [{

View File

@@ -92,7 +92,7 @@ from pretix.presale.signals import (
)
from pretix.presale.utils import customer_login
from pretix.presale.views import (
CartMixin, get_cart, get_cart_is_free, get_cart_total,
CartMixin, get_cart, get_cart_is_free, get_cart_position_sum,
)
from pretix.presale.views.cart import (
_items_from_post_data, cart_session, create_empty_cart_id,
@@ -1252,7 +1252,7 @@ class PaymentStep(CartMixin, TemplateFlowStep):
@cached_property
def _total_order_value(self):
cart = get_cart(self.request)
total = get_cart_total(self.request)
total = get_cart_position_sum(self.request)
try:
total += sum([
f.value for f in get_fees(
@@ -1415,7 +1415,7 @@ class PaymentStep(CartMixin, TemplateFlowStep):
return False
cart = get_cart(self.request)
total = get_cart_total(self.request)
total = get_cart_position_sum(self.request)
try:
total += sum([f.value for f in get_fees(self.request.event, self.request, total, self.invoice_address,
self.cart_session.get('payments', []), cart)])

View File

@@ -32,6 +32,7 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
import copy
import warnings
from collections import defaultdict
from datetime import datetime, timedelta
from decimal import Decimal
@@ -167,7 +168,6 @@ class CartMixin:
if not order:
apply_rounding(self.request.event.settings.tax_rounding, self.request.event.currency, [*lcp, *fees])
print([(p.price, p.tax_value, ) for p in lcp])
total = sum(p.price for p in lcp)
net_total = sum(p.price - p.tax_value for p in lcp)
@@ -378,7 +378,13 @@ def get_cart(request):
return request._cart_cache
def get_cart_total(request):
def get_cart_position_sum(request):
"""
Return an estimate of the current cart total. This estimate does not account for fees and
may not include proper rounding of taxes. This means it is useful e.g. as an input for
determining fees or determining e.g. which payment provider to offer, but is no reliable
estimate for the final order value.
"""
from pretix.presale.views.cart import get_or_create_cart_id
if not hasattr(request, '_cart_total_cache'):
@@ -391,6 +397,12 @@ def get_cart_total(request):
return request._cart_total_cache
def get_cart_total(request):
warnings.warn('Use get_cart_position_sum() instead of get_cart_total().',
DeprecationWarning)
return get_cart_position_sum(request)
def get_cart_invoice_address(request):
from pretix.presale.views.cart import cart_session
@@ -415,7 +427,7 @@ def get_cart_is_free(request):
cs = cart_session(request)
pos = get_cart(request)
ia = get_cart_invoice_address(request)
total = get_cart_total(request)
total = get_cart_position_sum(request)
try:
fees = get_fees(request.event, request, total, ia, cs.get('payments', []), pos)
except TaxRule.SaleNotAllowed: