Allow to exclude items from ticket generation explicitly

This commit is contained in:
Raphael Michel
2019-02-01 16:48:14 +01:00
parent f77b551aa6
commit 2aa246b3d5
16 changed files with 119 additions and 78 deletions

View File

@@ -79,7 +79,7 @@ class ItemSerializer(I18nAwareModelSerializer):
'position', 'picture', 'available_from', 'available_until',
'require_voucher', 'hide_without_voucher', 'allow_cancel',
'min_per_order', 'max_per_order', 'checkin_attention', 'has_variations',
'variations', 'addons', 'original_price', 'require_approval')
'variations', 'addons', 'original_price', 'require_approval', 'generate_tickets')
read_only_fields = ('has_variations', 'picture')
def get_serializer_context(self):

View File

@@ -114,9 +114,7 @@ class PositionDownloadsField(serializers.Field):
if instance.order.status != Order.STATUS_PAID:
if instance.order.status != Order.STATUS_PENDING or instance.order.require_approval or not instance.order.event.settings.ticket_download_pending:
return []
if instance.addon_to_id and not instance.order.event.settings.ticket_download_addons:
return []
if not instance.item.admission and not instance.order.event.settings.ticket_download_nonadm:
if not instance.generate_ticket:
return []
request = self.context['request']

View File

@@ -456,10 +456,8 @@ class OrderPositionViewSet(mixins.DestroyModelMixin, viewsets.ReadOnlyModelViewS
if pos.order.status != Order.STATUS_PAID:
raise PermissionDenied("Downloads are not available for unpaid orders.")
if pos.addon_to_id and not request.event.settings.ticket_download_addons:
raise PermissionDenied("Downloads are not enabled for add-on products.")
if not pos.item.admission and not request.event.settings.ticket_download_nonadm:
raise PermissionDenied("Downloads are not enabled for non-admission products.")
if not pos.generate_ticket:
raise PermissionDenied("Downloads are not enabled for this product.")
ct = CachedTicket.objects.filter(
order_position=pos, provider=provider.identifier, file__isnull=False

View File

@@ -0,0 +1,21 @@
# Generated by Django 2.1.5 on 2019-02-01 15:27
from django.db import migrations, models
import django.db.models.deletion
import jsonfallback.fields
import pretix.base.models.fields
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0107_auto_20190129_1337'),
]
operations = [
migrations.AddField(
model_name='item',
name='generate_tickets',
field=models.NullBooleanField(verbose_name='Allow ticket download'),
),
]

View File

@@ -287,6 +287,10 @@ class Item(LoggedModel):
),
default=False
)
generate_tickets = models.NullBooleanField(
verbose_name=_("Generate tickets"),
blank=True, null=True,
)
position = models.IntegerField(
default=0
)

View File

@@ -689,9 +689,7 @@ class Order(LockModel, LoggedModel):
@property
def positions_with_tickets(self):
for op in self.positions.all():
if op.addon_to_id and not self.event.settings.ticket_download_addons:
continue
if not op.item.admission and not self.event.settings.ticket_download_nonadm:
if not op.generate_ticket:
continue
yield op
@@ -1579,6 +1577,15 @@ class OrderPosition(AbstractPosition):
def sort_key(self):
return self.addon_to.positionid if self.addon_to else self.positionid, self.addon_to_id or 0
@property
def generate_ticket(self):
if self.item.generate_tickets is not None:
return self.item.generate_tickets
return (
(self.order.event.settings.ticket_download_addons or not self.addon_to_id) and
(self.event.settings.ticket_download_nonadm or self.item.admission)
)
@classmethod
def transform_cart_positions(cls, cp: List, order) -> list:
from . import Voucher

View File

@@ -297,6 +297,16 @@ class ItemCreateForm(I18nModelForm):
]
class TicketNullBooleanSelect(forms.NullBooleanSelect):
def __init__(self, attrs=None):
choices = (
('1', _('Choose automatically depending on event settings')),
('2', _('Yes, if ticket generation is enabled in general')),
('3', _('Never')),
)
super(forms.NullBooleanSelect, self).__init__(attrs, choices)
class ItemUpdateForm(I18nModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -340,6 +350,7 @@ class ItemUpdateForm(I18nModelForm):
'max_per_order',
'min_per_order',
'checkin_attention',
'generate_tickets',
'original_price'
]
field_classes = {
@@ -349,6 +360,7 @@ class ItemUpdateForm(I18nModelForm):
widgets = {
'available_from': SplitDateTimePickerWidget(),
'available_until': SplitDateTimePickerWidget(attrs={'data-date-after': '#id_available_from_0'}),
'generate_tickets': TicketNullBooleanSelect()
}

View File

@@ -43,6 +43,7 @@
<legend>{% trans "Additional settings" %}</legend>
{% bootstrap_field form.original_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field form.require_approval layout="control" %}
{% bootstrap_field form.generate_tickets layout="control" %}
{% for f in plugin_forms %}
{% bootstrap_form f layout="control" %}
{% endfor %}

View File

@@ -257,20 +257,18 @@
{% endif %}
{% if not line.canceled %}
<div class="position-buttons">
{% if not line.addon_to or request.event.settings.ticket_download_addons %}
{% if line.item.admission or request.event.settings.ticket_download_nonadm %}
{% for b in download_buttons %}
<form action="{% url "control:event.order.download.ticket" code=order.code event=request.event.slug organizer=request.event.organizer.slug position=line.pk output=b.identifier %}"
method="post" data-asynctask data-asynctask-download
class="form-inline helper-display-inline">
{% csrf_token %}
<button type="submit"
class="btn btn-xs btn-default">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
{% endif %}
{% if line.generate_ticket %}
{% for b in download_buttons %}
<form action="{% url "control:event.order.download.ticket" code=order.code event=request.event.slug organizer=request.event.organizer.slug position=line.pk output=b.identifier %}"
method="post" data-asynctask data-asynctask-download
class="form-inline helper-display-inline">
{% csrf_token %}
<button type="submit"
class="btn btn-xs btn-default">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
{% endif %}
{% eventsignal event "pretix.control.signals.order_position_buttons" order=order position=line request=request %}
</div>

View File

@@ -301,10 +301,8 @@ class OrderDownload(AsyncAction, OrderView):
return self.error(_('You requested an invalid ticket output type.'))
if not self.order_position:
raise Http404(_('Unknown order code or not authorized to access this order.'))
if 'position' in kwargs and (self.order_position.addon_to and not self.request.event.settings.ticket_download_addons):
return self.error(_('Ticket download is not enabled for add-on products.'))
if 'position' in kwargs and (not self.order_position.item.admission and not self.request.event.settings.ticket_download_nonadm):
return self.error(_('Ticket download is not enabled for non-admission products.'))
if 'position' in kwargs and not self.order_position.generate_ticket:
return self.error(_('Ticket download is not enabled for this product.'))
ct = self.get_last_ct()
if ct:

View File

@@ -77,9 +77,7 @@ class AllTicketsPDF(BaseExporter):
)
for op in qs:
if op.addon_to_id and not self.event.settings.ticket_download_addons:
continue
if not op.item.admission and not self.event.settings.ticket_download_nonadm:
if not op.generate_ticket:
continue
with language(op.order.locale):

View File

@@ -56,20 +56,18 @@
{% endif %}
</div>
{% if download and line.item.admission|default:event.settings.ticket_download_nonadm %}
{% if download and line.generate_ticket %}
<div class="download-desktop">
{% if not line.addon_to or event.settings.ticket_download_addons %}
{% for b in download_buttons %}
<form action="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
method="post" data-asynctask data-asynctask-download class="download-btn-form">
{% csrf_token %}
<button type="submit"
class="btn btn-sm {% if b.identifier == "pdf" %}btn-primary{% else %}btn-default{% endif %}">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
{% endif %}
{% for b in download_buttons %}
<form action="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
method="post" data-asynctask data-asynctask-download class="download-btn-form">
{% csrf_token %}
<button type="submit"
class="btn btn-sm {% if b.identifier == "pdf" %}btn-primary{% else %}btn-default{% endif %}">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
</div>
{% elif line.addon_to %}
<div class="count">&nbsp;</div>
@@ -149,20 +147,18 @@
{% endif %}
{% endif %}
</div>
{% if download and line.item.admission|default:event.settings.ticket_download_nonadm %}
{% if download and line.generate_ticket %}
<div class="download-mobile">
{% if not line.addon_to or event.settings.ticket_download_addons %}
{% for b in download_buttons %}
<form action="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
method="post" data-asynctask data-asynctask-download class="download-btn-form">
{% csrf_token %}
<button type="submit"
class="btn btn-sm {% if b.identifier == "pdf" %}btn-primary{% else %}btn-default{% endif %}">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
{% endif %}
{% for b in download_buttons %}
<form action="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
method="post" data-asynctask data-asynctask-download class="download-btn-form">
{% csrf_token %}
<button type="submit"
class="btn btn-sm {% if b.identifier == "pdf" %}btn-primary{% else %}btn-default{% endif %}">
<span class="fa {{ b.icon }}"></span> {{ b.text }}
</button>
</form>
{% endfor %}
</div>
{% endif %}
<div class="clearfix"></div>

View File

@@ -102,8 +102,7 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TemplateView):
order=self.order
)
ctx['can_download_multi'] = any([b['multi'] for b in self.download_buttons]) and (
self.request.event.settings.ticket_download_nonadm or
[p.item.admission for p in ctx['cart']['positions']].count(True) > 1
[p.generate_ticket for p in ctx['cart']['positions']].count(True) > 1
)
ctx['invoices'] = list(self.order.invoices.all())
can_generate_invoice = (
@@ -685,10 +684,8 @@ class OrderDownload(EventViewMixin, OrderDetailMixin, AsyncAction, View):
raise Http404(_('Unknown order code or not authorized to access this order.'))
if not self.order.ticket_download_available:
return self.error(_('Ticket download is not (yet) enabled for this order.'))
if 'position' in kwargs and (self.order_position.addon_to and not self.request.event.settings.ticket_download_addons):
return self.error(_('Ticket download is not enabled for add-on products.'))
if 'position' in kwargs and (not self.order_position.item.admission and not self.request.event.settings.ticket_download_nonadm):
return self.error(_('Ticket download is not enabled for non-admission products.'))
if 'position' in kwargs and not self.order_position.generate_ticket:
return self.error(_('Ticket download is not enabled for this product.'))
ct = self.get_last_ct()
if ct: