-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement voucher per event and for all events of an organizer | Crea…
…te Voucher (#473) * Implement voucher for invoise create/update pages * Implement invoice voucher delete view * show currency in invoice voucher page update * optimize import * change migration file name * fix isort, flake8 --------- Co-authored-by: lcduong <[email protected]>
- Loading branch information
Showing
12 changed files
with
516 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Generated by Django 5.1.3 on 2024-11-12 08:04 | ||
|
||
from django.db import migrations, models | ||
|
||
import pretix.base.models.base | ||
import pretix.base.models.vouchers | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("pretixbase", "0005_page_alter_cachedcombinedticket_id_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="InvoiceVoucher", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False | ||
), | ||
), | ||
( | ||
"code", | ||
models.CharField( | ||
db_index=True, | ||
default=pretix.base.models.vouchers.generate_code, | ||
max_length=255, | ||
unique=True, | ||
), | ||
), | ||
("max_usages", models.PositiveIntegerField(default=1)), | ||
("redeemed", models.PositiveIntegerField(default=0)), | ||
( | ||
"budget", | ||
models.DecimalField(decimal_places=2, max_digits=10, null=True), | ||
), | ||
( | ||
"valid_until", | ||
models.DateTimeField(blank=True, db_index=True, null=True), | ||
), | ||
("price_mode", models.CharField(default="none", max_length=100)), | ||
( | ||
"value", | ||
models.DecimalField(decimal_places=2, max_digits=10, null=True), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("created_by", models.CharField(default="system", max_length=50)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("updated_by", models.CharField(default="system", max_length=50)), | ||
( | ||
"limit_events", | ||
models.ManyToManyField( | ||
related_name="invoice_vouchers", to="pretixbase.event" | ||
), | ||
), | ||
( | ||
"limit_organizer", | ||
models.ManyToManyField( | ||
related_name="invoice_vouchers", to="pretixbase.organizer" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Invoice Voucher", | ||
"verbose_name_plural": "Invoice Vouchers", | ||
"ordering": ("code",), | ||
}, | ||
bases=(models.Model, pretix.base.models.base.LoggingMixin), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
from django_scopes import scopes_disabled | ||
|
||
from pretix.base.forms import I18nModelForm | ||
from pretix.base.forms.widgets import SplitDateTimePickerWidget | ||
from pretix.base.models import Event, Organizer | ||
from pretix.base.models.vouchers import InvoiceVoucher | ||
from pretix.control.forms import SplitDateTimeField | ||
|
||
|
||
class InvoiceVoucherForm(I18nModelForm): | ||
event_effect = forms.ModelMultipleChoiceField( | ||
queryset=Event.objects.none(), | ||
widget=forms.CheckboxSelectMultiple, | ||
required=False, | ||
label=_("Event effect"), | ||
help_text=_("The voucher will only be valid for the selected events.") | ||
) | ||
organizer_effect = forms.ModelMultipleChoiceField( | ||
queryset=Organizer.objects.none(), | ||
widget=forms.CheckboxSelectMultiple, | ||
required=False, | ||
label=_("Organizer effect"), | ||
help_text=_("The voucher will be valid for all events under the selected organizers.") | ||
) | ||
|
||
class Meta: | ||
model = InvoiceVoucher | ||
localized_fields = '__all__' | ||
fields = [ | ||
'code', 'valid_until', 'value', 'max_usages', 'price_mode', 'budget', 'event_effect', 'organizer_effect' | ||
] | ||
field_classes = { | ||
'valid_until': SplitDateTimeField, | ||
} | ||
widgets = { | ||
'valid_until': SplitDateTimePickerWidget(), | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
instance = kwargs.get('instance') | ||
super().__init__(*args, **kwargs) | ||
if instance: | ||
self.fields['event_effect'].initial = instance.limit_events.all() | ||
self.fields['organizer_effect'].initial = instance.limit_organizer.all() | ||
with scopes_disabled(): | ||
self.fields['event_effect'].queryset = Event.objects.all() | ||
self.fields['organizer_effect'].queryset = Organizer.objects.all() | ||
|
||
def clean(self): | ||
data = super().clean() | ||
return data | ||
|
||
def save(self, commit=True): | ||
instance = super().save(commit=False) | ||
|
||
if commit: | ||
instance.save() | ||
|
||
instance.limit_events.set(self.cleaned_data.get('event_effect', [])) | ||
instance.limit_organizer.set(self.cleaned_data.get('organizer_effect', [])) | ||
|
||
if commit: | ||
self.save_m2m() | ||
|
||
return instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/pretix/control/templates/pretixcontrol/admin/vouchers/delete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends "pretixcontrol/admin/base.html" %} | ||
{% load i18n %} | ||
{% load bootstrap3 %} | ||
{% block title %}{% trans "Delete voucher" %}{% endblock %} | ||
{% block content %} | ||
<h1>{% trans "Delete voucher" %}</h1> | ||
<form action="" method="post" class="form-horizontal"> | ||
{% csrf_token %} | ||
<p>{% blocktrans %}Are you sure you want to delete the voucher <strong>{{ invoice_voucher }}</strong>?{% endblocktrans %}</p> | ||
<div class="form-group submit-group"> | ||
<a href='{% url "control:admin.vouchers" %}' class="btn btn-default btn-cancel"> | ||
{% trans "Cancel" %} | ||
</a> | ||
<button type="submit" class="btn btn-delete btn-danger btn-save"> | ||
{% trans "Delete" %} | ||
</button> | ||
</div> | ||
</form> | ||
{% endblock %} |
43 changes: 43 additions & 0 deletions
43
src/pretix/control/templates/pretixcontrol/admin/vouchers/detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% extends "pretixcontrol/admin/base.html" %} | ||
{% load i18n %} | ||
{% load bootstrap3 %} | ||
{% block title %}{% trans "Voucher" %}{% endblock %} | ||
{% block content %} | ||
<h1>{% trans "Voucher" %}</h1> | ||
{% if voucher.redeemed %} | ||
<div class="alert alert-warning"> | ||
{% trans "This voucher already has been used. It is not recommended to modify it." %} | ||
</div> | ||
{% endif %} | ||
<form action="" method="post" class="form-horizontal"> | ||
{% csrf_token %} | ||
{% bootstrap_form_errors form %} | ||
<div class="row"> | ||
<div class="col-xs-12 col-lg-10"> | ||
<fieldset> | ||
<legend>{% trans "Voucher details" %}</legend> | ||
{% bootstrap_field form.code layout="control" %} | ||
{% bootstrap_field form.max_usages layout="control" %} | ||
{% bootstrap_field form.valid_until layout="control" %} | ||
<div class="form-group"> | ||
<label class="col-md-3 control-label" >{% trans "Price effect" %}</label> | ||
<div class="col-md-5"> | ||
{% bootstrap_field form.price_mode show_label=False form_group_class="" %} | ||
</div> | ||
<div class="col-md-4"> | ||
{% bootstrap_field form.value show_label=False form_group_class="" %} | ||
</div> | ||
</div> | ||
{% bootstrap_field form.budget addon_after=currency layout="control" %} | ||
{% bootstrap_field form.event_effect layout="control" %} | ||
{% bootstrap_field form.organizer_effect layout="control" %} | ||
</fieldset> | ||
</div> | ||
</div> | ||
<div class="form-group submit-group"> | ||
<button type="submit" class="btn btn-primary btn-save"> | ||
{% trans "Save" %} | ||
</button> | ||
</div> | ||
</form> | ||
{% endblock %} |
76 changes: 76 additions & 0 deletions
76
src/pretix/control/templates/pretixcontrol/admin/vouchers/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{% extends "pretixcontrol/admin/base.html" %} | ||
{% load i18n %} | ||
{% load bootstrap3 %} | ||
{% load urlreplace %} | ||
{% load money %} | ||
{% block title %}{% trans "Vouchers" %}{% endblock %} | ||
{% block content %} | ||
<h1>{% trans "Vouchers" %}</h1> | ||
{% if vouchers|length == 0 %} | ||
<div class="empty-collection"> | ||
<p> | ||
{% blocktrans trimmed %} | ||
You haven't created any vouchers yet. | ||
{% endblocktrans %} | ||
</p> | ||
|
||
<a href='{% url "control:admin.vouchers.add" %}' | ||
class="btn btn-primary btn-lg"><i class="fa fa-plus"></i> {% trans "Create a new voucher" %}</a> | ||
</div> | ||
{% else %} | ||
<p> | ||
<a href='{% url "control:admin.vouchers.add" %}' | ||
class="btn btn-primary btn-lg"><i class="fa fa-plus"></i> {% trans "Create a new voucher" %}</a> | ||
</p> | ||
<form action='{% url "control:admin.vouchers" %}' method="post"> | ||
{% csrf_token %} | ||
<div class="table-responsive"> | ||
<table class="table table-hover table-quotas"> | ||
<thead> | ||
<tr> | ||
<th> | ||
{% trans "Voucher code" %} | ||
<a href="?{% url_replace request 'ordering' '-code' %}"><i class="fa fa-caret-down"></i></a> | ||
<a href="?{% url_replace request 'ordering' 'code' %}"><i class="fa fa-caret-up"></i></a> | ||
</th> | ||
<th> | ||
{% trans "Redemptions" %} | ||
<a href="?{% url_replace request 'ordering' '-redeemed' %}"><i class="fa fa-caret-down"></i></a> | ||
<a href="?{% url_replace request 'ordering' 'redeemed' %}"><i class="fa fa-caret-up"></i></a> | ||
</th> | ||
<th> | ||
{% trans "Expiry" %} | ||
<a href="?{% url_replace request 'ordering' '-valid_until' %}"><i class="fa fa-caret-down"></i></a> | ||
<a href="?{% url_replace request 'ordering' 'valid_until' %}"><i class="fa fa-caret-up"></i></a> | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for v in vouchers %} | ||
<tr> | ||
<td> | ||
{% if not v.is_active %} | ||
<del> | ||
{% endif %} | ||
<strong><a href='{% url "control:admin.voucher" voucher=v.id %}'>{{ v.code }}</a></strong> | ||
{% if not v.is_active %} | ||
</del> | ||
{% endif %} | ||
</td> | ||
<td> | ||
{{ v.redeemed }} / {{ v.max_usages }} | ||
</td> | ||
<td>{{ v.valid_until|date }}</td> | ||
<td class="text-right flip"> | ||
<a href='{% url "control:admin.voucher.delete" voucher=v.id %}' class="btn btn-delete btn-danger btn-sm"><i class="fa fa-trash"></i></a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</form> | ||
{% include "pretixcontrol/pagination.html" %} | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.