Fix redemption of multiple gift cards

This commit is contained in:
Raphael Michel
2020-09-18 18:20:08 +02:00
parent af2b4ebb4b
commit 59655dca82
3 changed files with 42 additions and 4 deletions

View File

@@ -1134,7 +1134,7 @@ class GiftCardPayment(BasePaymentProvider):
cart['raw']
)
total += sum([f.value for f in fees])
remainder = total - gc.value
remainder = total
if remainder > Decimal('0.00'):
del cs['payment']
messages.success(request, _("Your gift card has been applied, but {} still need to be paid. Please select a payment method.").format(

View File

@@ -1085,16 +1085,14 @@ def get_fees(event, request, total, invoice_address, provider, positions):
if cs.get('gift_cards'):
gcs = cs['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:
if gc.testmode != event.testmode:
gcs.remove(gc.pk)
continue
fval = Decimal(gc.value) # TODO: don't require an extra query
fval = min(fval, total - summed)
fval = min(fval, total)
if fval > 0:
total -= fval
summed += fval
fees.append(OrderFee(
fee_type=OrderFee.FEE_TYPE_GIFTCARD,
internal_type='giftcard',