From b142e1d433471667c01b165b087fce95da576397 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 1 Apr 2020 17:10:19 +0200 Subject: [PATCH] Allow to drop fees if paid with gift card --- pretix_servicefees/signals.py | 13 +++++++++++++ .../templates/pretix_servicefees/settings.html | 1 + pretix_servicefees/views.py | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/pretix_servicefees/signals.py b/pretix_servicefees/signals.py index dee8fa8..b107a4b 100644 --- a/pretix_servicefees/signals.py +++ b/pretix_servicefees/signals.py @@ -12,6 +12,7 @@ from pretix.base.templatetags.money import money_filter from pretix.control.signals import nav_event_settings from pretix.presale.signals import fee_calculation_for_cart, front_page_top, order_meta_from_request from pretix.presale.views import get_cart +from pretix.presale.views.cart import cart_session @receiver(nav_event_settings, dispatch_uid='service_fee_nav_settings') @@ -48,6 +49,18 @@ def get_fees(event, total, invoice_address, mod='', request=None, positions=[]): fee_abs = Decimal("0") if fee_abs is None else fee_abs fee_percent = Decimal("0") if fee_percent is None else fee_percent + if event.settings.get('service_fee_skip_if_gift_card', as_type=bool): + cs = cart_session(request) + if cs.get('gift_cards'): + gc_qs = event.organizer.accepted_gift_cards.filter(pk__in=cs.get('gift_cards'), currency=event.currency) + summed = 0 + for gc in gc_qs: + fval = Decimal(gc.value) # TODO: don't require an extra query + fval = min(fval, total - summed) + if fval > 0: + total -= fval + summed += fval + if (fee_per_ticket or fee_abs or fee_percent) and total != Decimal('0.00'): fee = round_decimal(fee_abs + total * (fee_percent / 100) + len(positions) * fee_per_ticket, event.currency) tax_rule = event.settings.tax_rate_default or TaxRule.zero() diff --git a/pretix_servicefees/templates/pretix_servicefees/settings.html b/pretix_servicefees/templates/pretix_servicefees/settings.html index 98ea886..b67cb78 100644 --- a/pretix_servicefees/templates/pretix_servicefees/settings.html +++ b/pretix_servicefees/templates/pretix_servicefees/settings.html @@ -11,6 +11,7 @@ {% bootstrap_field form.service_fee_per_ticket addon_after=request.event.currency layout="control" %} {% bootstrap_field form.service_fee_abs addon_after=request.event.currency layout="control" %} {% bootstrap_field form.service_fee_percent addon_after="%" layout="control" %} + {% bootstrap_field form.service_fee_skip_if_gift_card layout="control" %}
{% trans "Service fees with resellers" %} diff --git a/pretix_servicefees/views.py b/pretix_servicefees/views.py index 67d4c84..ec60305 100644 --- a/pretix_servicefees/views.py +++ b/pretix_servicefees/views.py @@ -25,6 +25,14 @@ class ServiceFeeSettingsForm(SettingsForm): help_text=_('This fee will be added for each ticket sold, except for free items and addons.'), required=False ) + service_fee_skip_if_gift_card = forms.BooleanField( + label=_('Do not charge service fee on tickets paid with gift cards'), + help_text=_('If a gift card is used for the payment, the percentual fees will be applied on the value of the ' + 'tickets minus the value of the gift cards. All fixed fees will be dropped if the tickets can ' + 'be paid with gift cards entirely. This only works if the gift card is redeemd when the order is ' + 'submitted, not if it\'s used to pay an unpaid order later.'), + required=False + ) service_fee_abs_resellers = forms.DecimalField( label=_('Fixed fee per order'),