forked from CGM_Public/pretix_original
Cross-organizer acceptance
This commit is contained in:
@@ -2,6 +2,7 @@ import string
|
||||
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -90,6 +91,16 @@ class Organizer(LoggedModel):
|
||||
default=lambda: self.issued_gift_cards.exists() or self.gift_card_issuer_acceptance.exists()
|
||||
)
|
||||
|
||||
@property
|
||||
def accepted_gift_cards(self):
|
||||
from .giftcards import GiftCard, GiftCardAcceptance
|
||||
|
||||
return GiftCard.objects.annotate(
|
||||
accepted=Exists(GiftCardAcceptance.objects.filter(issuer=OuterRef('issuer'), collector=self))
|
||||
).filter(
|
||||
Q(issuer=self) | Q(accepted=True)
|
||||
)
|
||||
|
||||
def allow_delete(self):
|
||||
from . import Order, Invoice
|
||||
return (
|
||||
|
||||
@@ -14,8 +14,8 @@ from django_scopes import scopes_disabled
|
||||
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.models import (
|
||||
CartPosition, Event, GiftCard, InvoiceAddress, Item, ItemBundle,
|
||||
ItemVariation, Seat, SeatCategoryMapping, Voucher,
|
||||
CartPosition, Event, InvoiceAddress, Item, ItemBundle, ItemVariation, Seat,
|
||||
SeatCategoryMapping, Voucher,
|
||||
)
|
||||
from pretix.base.models.event import SubEvent
|
||||
from pretix.base.models.orders import OrderFee
|
||||
@@ -970,7 +970,7 @@ def get_fees(event, request, total, invoice_address, provider):
|
||||
|
||||
cs = cart_session(request)
|
||||
if cs.get('gift_cards'):
|
||||
gc_qs = GiftCard.objects.filter(pk__in=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
|
||||
|
||||
@@ -534,8 +534,7 @@ class PaymentStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
|
||||
if request.POST.get("giftcard") and request.POST.get("payment") == "giftcard":
|
||||
# TODO: cross-organizer acceptance, …
|
||||
try:
|
||||
gc = GiftCard.objects.get(
|
||||
issuer=request.organizer,
|
||||
gc = request.organizer.accepted_gift_cards.get(
|
||||
secret=request.POST.get("giftcard")
|
||||
)
|
||||
if gc.currency != request.event.currency:
|
||||
|
||||
Reference in New Issue
Block a user