-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement voucher per event and for all events of an organizer | Create Voucher #473
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35b6968
Implement voucher for invoise create/update pages
lcduong c7b246b
Implement invoice voucher delete view
lcduong bb8fcfe
show currency in invoice voucher page update
lcduong e5e5711
Merge branch 'development' into feature-382
lcduong 6a2cdf7
optimize import
lcduong 1bed56b
change migration file name
lcduong a03d534
Merge branch 'development' into feature-382
odkhang 6e1ec95
fix isort, flake8
odkhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This override is unnecessary.