forked from CGM_Public/pretix_original
Add expiry dates and individual conditions to gift cards (#1656)
* Add expiry dates and individual conditions to gift cards * Display refund gift cards with more details and prettier interface * Allow to set gift card expiry and conditions when cancelling event * Extend gift card search * Fix #1565 -- Some gift card filters * Improve list of gift cards * Allow to edit gift cards * Note on validity
This commit is contained in:
@@ -5,7 +5,8 @@ from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Sum
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
|
||||
from pretix.base.banlist import banned
|
||||
from pretix.base.models import LoggedModel
|
||||
@@ -62,12 +63,22 @@ class GiftCard(LoggedModel):
|
||||
verbose_name=_('Test mode card'),
|
||||
default=False
|
||||
)
|
||||
expires = models.DateTimeField(
|
||||
null=True, blank=True, verbose_name=_('Expiry date')
|
||||
)
|
||||
conditions = models.TextField(
|
||||
null=True, blank=True, verbose_name=pgettext_lazy('giftcard', 'Special terms and conditions')
|
||||
)
|
||||
CURRENCY_CHOICES = [(c.alpha_3, c.alpha_3 + " - " + c.name) for c in settings.CURRENCIES]
|
||||
currency = models.CharField(max_length=10, choices=CURRENCY_CHOICES)
|
||||
|
||||
def __str__(self):
|
||||
return self.secret
|
||||
|
||||
@property
|
||||
def expired(self):
|
||||
return self.expires and now() > self.expires
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self.transactions.aggregate(s=Sum('value'))['s'] or Decimal('0.00')
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import string
|
||||
from datetime import date, datetime, time
|
||||
|
||||
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.timezone import get_current_timezone, make_aware, now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from pretix.base.models.base import LoggedModel
|
||||
@@ -101,6 +103,15 @@ class Organizer(LoggedModel):
|
||||
Q(issuer=self) | Q(accepted=True)
|
||||
)
|
||||
|
||||
@property
|
||||
def default_gift_card_expiry(self):
|
||||
if self.settings.giftcard_expiry_years is not None:
|
||||
tz = get_current_timezone()
|
||||
return make_aware(datetime.combine(
|
||||
date(now().astimezone(tz).year + self.settings.get('giftcard_expiry_years', as_type=int), 12, 31),
|
||||
time(hour=23, minute=59, second=59)
|
||||
), tz)
|
||||
|
||||
def allow_delete(self):
|
||||
from . import Order, Invoice
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user