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" %}