This commit is contained in:
Raphael Michel 2022-11-23 14:53:01 +01:00 committed by GitHub
parent 0f7476a5d3
commit 97fa4b2bfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,7 +31,7 @@ def navbar_settings(sender, request, **kwargs):
}] }]
def get_fees(event, total, invoice_address, mod='', request=None, positions=[], gift_cards=None): def get_fees(event, total, invoice_address, mod='', request=None, positions=[], gift_cards=None, payment_requests=None):
if request is not None and not positions: if request is not None and not positions:
positions = get_cart(request) positions = get_cart(request)
@ -64,18 +64,25 @@ def get_fees(event, total, invoice_address, mod='', request=None, positions=[],
fee_percent = Decimal("0") if fee_percent is None else fee_percent 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): if event.settings.get('service_fee_skip_if_gift_card', as_type=bool):
gift_cards = gift_cards or [] if payment_requests is not None:
if request: for p in payment_requests:
cs = cart_session(request) if p['provider'] == 'giftcard':
if cs.get('gift_cards'): total = max(0, total - Decimal(p['max_value'] or '0'))
gift_cards = event.organizer.accepted_gift_cards.filter(pk__in=cs.get('gift_cards'), currency=event.currency)
summed = 0 else:
for gc in gift_cards: # pretix pre 4.15
fval = Decimal(gc.value) # TODO: don't require an extra query gift_cards = gift_cards or []
fval = min(fval, total - summed) if request:
if fval > 0: cs = cart_session(request)
total -= fval if cs.get('gift_cards'):
summed += fval gift_cards = event.organizer.accepted_gift_cards.filter(pk__in=cs.get('gift_cards'), currency=event.currency)
summed = 0
for gc in gift_cards:
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'): if (fee_per_ticket or fee_abs or fee_percent) and total != Decimal('0.00'):
tax_rule_zero = TaxRule.zero() tax_rule_zero = TaxRule.zero()
@ -146,7 +153,7 @@ def cart_fee(sender: Event, request: HttpRequest, invoice_address, total, **kwar
pass pass
else: else:
mod = '_resellers' mod = '_resellers'
return get_fees(sender, total, invoice_address, mod, request) return get_fees(sender, total, invoice_address, mod, request, payment_requests=kwargs.get('payment_requests'))
@receiver(order_fee_calculation, dispatch_uid="service_fee_calc_order") @receiver(order_fee_calculation, dispatch_uid="service_fee_calc_order")
@ -164,7 +171,8 @@ def order_fee(sender: Event, positions, invoice_address, total, meta_info, gift_
if config.skip_default_service_fees: if config.skip_default_service_fees:
return [] return []
return get_fees(sender, total, invoice_address, mod, positions=positions, gift_cards=gift_cards) return get_fees(sender, total, invoice_address, mod, positions=positions, gift_cards=gift_cards,
payment_requests=kwargs.get('payment_requests'))
@receiver(front_page_top, dispatch_uid="service_fee_front_page_top") @receiver(front_page_top, dispatch_uid="service_fee_front_page_top")