From 8f112f8d9a13fae62ef50fb6e20de35c1e920c97 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 4 Nov 2019 11:00:48 +0100 Subject: [PATCH] Pass cart positions to fee_calculation_for_cart --- src/pretix/base/payment.py | 3 ++- src/pretix/base/services/cart.py | 4 ++-- src/pretix/presale/checkoutflow.py | 4 +++- src/pretix/presale/signals.py | 3 ++- src/pretix/presale/views/__init__.py | 8 ++++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pretix/base/payment.py b/src/pretix/base/payment.py index e8f18e5c5e..8553e217dd 100644 --- a/src/pretix/base/payment.py +++ b/src/pretix/base/payment.py @@ -702,8 +702,9 @@ class FreeOrderProvider(BasePaymentProvider): def is_allowed(self, request: HttpRequest, total: Decimal=None) -> bool: from .services.cart import get_fees + cart = get_cart(request) total = get_cart_total(request) - total += sum([f.value for f in get_fees(self.event, request, total, None, None)]) + total += sum([f.value for f in get_fees(self.event, request, total, None, None, cart)]) return total == 0 def order_change_allowed(self, order: Order) -> bool: diff --git a/src/pretix/base/services/cart.py b/src/pretix/base/services/cart.py index a8146e5706..d35b048146 100644 --- a/src/pretix/base/services/cart.py +++ b/src/pretix/base/services/cart.py @@ -958,12 +958,12 @@ def update_tax_rates(event: Event, cart_id: str, invoice_address: InvoiceAddress return totaldiff -def get_fees(event, request, total, invoice_address, provider): +def get_fees(event, request, total, invoice_address, provider, positions): from pretix.presale.views.cart import cart_session fees = [] for recv, resp in fee_calculation_for_cart.send(sender=event, request=request, invoice_address=invoice_address, - total=total): + total=total, positions=positions): if resp: fees += resp diff --git a/src/pretix/presale/checkoutflow.py b/src/pretix/presale/checkoutflow.py index 89c6af2851..d2a3898412 100644 --- a/src/pretix/presale/checkoutflow.py +++ b/src/pretix/presale/checkoutflow.py @@ -505,8 +505,10 @@ class PaymentStep(QuestionsViewMixin, CartMixin, TemplateFlowStep): @cached_property def _total_order_value(self): + cart = get_cart(self.request) total = get_cart_total(self.request) - total += sum([f.value for f in get_fees(self.request.event, self.request, total, self.invoice_address, None)]) + total += sum([f.value for f in get_fees(self.request.event, self.request, total, self.invoice_address, None, + cart)]) return Decimal(total) @cached_property diff --git a/src/pretix/presale/signals.py b/src/pretix/presale/signals.py index fb15d2e21f..95b2162740 100644 --- a/src/pretix/presale/signals.py +++ b/src/pretix/presale/signals.py @@ -119,7 +119,7 @@ argument will contain the request object. """ fee_calculation_for_cart = EventPluginSignal( - providing_args=['request', 'invoice_address', 'total'] + providing_args=['request', 'invoice_address', 'total', 'positions'] ) """ This signals allows you to add fees to a cart. You are expected to return a list of ``OrderFee`` @@ -129,6 +129,7 @@ As with all plugin signals, the ``sender`` keyword argument will contain the eve argument will contain the request object and ``invoice_address`` the invoice address (useful for tax calculation). The ``total`` keyword argument will contain the total cart sum without any fees. You should not rely on this ``total`` value for fee calculations as other fees might interfere. +The ``positions`` argument will contain a list or queryset of ``CartPosition`` objects. """ contact_form_fields = EventPluginSignal( diff --git a/src/pretix/presale/views/__init__.py b/src/pretix/presale/views/__init__.py index 927c5f0227..e21b3b7e44 100644 --- a/src/pretix/presale/views/__init__.py +++ b/src/pretix/presale/views/__init__.py @@ -133,7 +133,10 @@ class CartMixin: if order: fees = order.fees.all() elif positions: - fees = get_fees(self.request.event, self.request, total, self.invoice_address, self.cart_session.get('payment')) + fees = get_fees( + self.request.event, self.request, total, self.invoice_address, self.cart_session.get('payment'), + cartpos + ) else: fees = [] @@ -231,9 +234,10 @@ def get_cart_is_free(request): if not hasattr(request, '_cart_free_cache'): cs = cart_session(request) + pos = get_cart(request) ia = get_cart_invoice_address(request) total = get_cart_total(request) - fees = get_fees(request.event, request, total, ia, cs.get('payment')) + fees = get_fees(request.event, request, total, ia, cs.get('payment'), pos) request._cart_free_cache = total + sum(f.value for f in fees) == Decimal('0.00') return request._cart_free_cache