Backend management of gift cards

This commit is contained in:
Raphael Michel
2019-09-18 18:49:51 +02:00
parent ed370fa913
commit 85e7a16880
14 changed files with 404 additions and 12 deletions

View File

@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
('issuance', models.DateTimeField(auto_now_add=True)),
('secret', models.CharField(db_index=True, default=pretix.base.models.giftcards.gen_giftcard_secret, max_length=190, unique=True)),
('currency', models.CharField(max_length=10)),
('issued_in', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='issued_gift_cards', to='pretixbase.OrderPosition')),
('issued_in', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='issued_gift_cards', to='pretixbase.OrderPosition', null=True, blank=True)),
('issuer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='issued_gift_cards', to='pretixbase.Organizer')),
],
),

View File

@@ -0,0 +1,29 @@
# Generated by Django 2.2.1 on 2019-09-18 15:37
import django.db.models.deletion
from django.db import migrations, models
import pretix.base.models.fields
def fwd(app, schema_editor):
Team = app.get_model('pretixbase', 'Team')
Team.objects.filter(can_change_organizer_settings=True).update(can_manage_gift_cards=True)
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0135_auto_20190910_2020'),
]
operations = [
migrations.AddField(
model_name='team',
name='can_manage_gift_cards',
field=models.BooleanField(default=False),
),
migrations.RunPython(
fwd, migrations.RunPython.noop
),
]

View File

@@ -730,7 +730,7 @@ class Event(EventMixin, LoggedModel):
def has_payment_provider(self):
result = False
for provider in self.get_payment_providers().values():
if provider.is_enabled and provider.identifier not in ('free', 'boxoffice', 'offsetting'):
if provider.is_enabled and provider.identifier not in ('free', 'boxoffice', 'offsetting', 'giftcard'):
result = True
break
return result

View File

@@ -4,6 +4,9 @@ from django.conf import settings
from django.db import models
from django.db.models import Sum
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
from pretix.base.models import LoggedModel
def gen_giftcard_secret():
@@ -27,7 +30,7 @@ class GiftCardAcceptance(models.Model):
)
class GiftCard(models.Model):
class GiftCard(LoggedModel):
issuer = models.ForeignKey(
'Organizer',
related_name='issued_gift_cards',
@@ -37,6 +40,7 @@ class GiftCard(models.Model):
'OrderPosition',
related_name='issued_gift_cards',
on_delete=models.PROTECT,
null=True, blank=True
)
issuance = models.DateTimeField(
auto_now_add=True,
@@ -46,8 +50,13 @@ class GiftCard(models.Model):
default=gen_giftcard_secret,
unique=True,
db_index=True,
verbose_name=_('Gift card code'),
)
currency = models.CharField(max_length=10)
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 value(self):
@@ -88,3 +97,6 @@ class GiftCardTransaction(models.Model):
blank=True,
on_delete=models.PROTECT
)
class Meta:
ordering = ("datetime",)

View File

@@ -156,6 +156,10 @@ class Team(LoggedModel):
help_text=_('Someone with this setting can get access to most data of all of your events, i.e. via privacy '
'reports, so be careful who you add to this team!')
)
can_manage_gift_cards = models.BooleanField(
default=False,
verbose_name=_("Can manage gift cards")
)
can_change_event_settings = models.BooleanField(
default=False,