Add new gift card to orderposition relationship (#3291)

This commit is contained in:
Raphael Michel
2023-05-09 09:54:46 +02:00
committed by GitHub
parent 996621c028
commit 6fac1aeb62
26 changed files with 477 additions and 64 deletions

View File

@@ -369,6 +369,20 @@
{% endif %}
<div class="clearfix"></div>
</div>
{% for gc in line.owned_gift_cards.all %}
<div class="cart-row-giftcard">
<span class="fa fa-credit-card" aria-hidden="true"></span>
<strong>{% trans "Gift card" %}</strong>
<code>{{ gc.secret }}</code>
<strong>{% trans "Current value:" %}</strong>
{{ gc.value|money:gc.currency }}
<a href="{% if position_page and line.addon_to %}{% eventurl event "presale:event.order.position.giftcard" secret=line.addon_to.web_secret order=order.code pk=gc.pk position=line.addon_to.positionid %}{% elif position_page %}{% eventurl event "presale:event.order.position.giftcard" secret=line.web_secret order=order.code pk=gc.pk position=line.positionid %}{% else %}{% eventurl event "presale:event.order.giftcard" secret=order.secret order=order.code pk=gc.pk %}{% endif %}"
class="btn btn-default btn-sm">
<span class="fa fa-eye" aria-hidden="true"></span>
{% trans "Details" %}
</a>
</div>
{% endfor %}
{% endfor %}
{% for fee in cart.fees %}
<div class="row cart-row">

View File

@@ -0,0 +1,29 @@
{% load i18n %}
{% load money %}
<table class="panel-body table">
<thead>
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "Order" %}</th>
<th class="text-right">{% trans "Value" %}</th>
</tr>
</thead>
<tbody>
{% for t in transactions %}
<tr>
<td>{{ t.datetime|date:"SHORT_DATETIME_FORMAT" }}</td>
<td>
{% if t.order %}
{{ t.order.full_code }}
{% else %}
<em>{% if t.text %}{{ t.text }}{% else %}{% trans "Manual transaction" %}{% endif %}</em>
{% endif %}
</td>
<td class="text-right">
{{ t.value|money:giftcard.currency }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include "pretixcontrol/pagination.html" %}

View File

@@ -0,0 +1,24 @@
{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load money %}
{% load eventurl %}
{% load l10n %}
{% load rich_text %}
{% block title %}{% trans "Gift card" %}{% endblock %}
{% block content %}
<h2>
{% blocktrans trimmed with code=giftcard.secret %}
Gift card: {{ code }}
{% endblocktrans %}
<a href="{% eventurl request.event "presale:event.order" secret=order.secret order=order.code %}"
class="btn btn-default btn-sm btn-link">
<span class="fa fa-caret-left"></span>
{% trans "Back" %}
</a>
</h2>
<p>
<strong>{% trans "Current value:" %} {{ giftcard.value|money:giftcard.currency }}</strong>
</p>
<h3>{% trans "Transaction history" %}</h3>
{% include "pretixpresale/event/fragment_giftcard_history.html" %}
{% endblock %}

View File

@@ -0,0 +1,24 @@
{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load money %}
{% load eventurl %}
{% load l10n %}
{% load rich_text %}
{% block title %}{% trans "Gift card" %}{% endblock %}
{% block content %}
<h2>
{% blocktrans trimmed with code=giftcard.secret %}
Gift card: {{ code }}
{% endblocktrans %}
<a href="{% eventurl request.event "presale:event.order.position" secret=position.web_secret order=order.code position=position.positionid %}"
class="btn btn-default btn-sm btn-link">
<span class="fa fa-caret-left"></span>
{% trans "Back" %}
</a>
</h2>
<p>
<strong>{% trans "Current value:" %} {{ giftcard.value|money:giftcard.currency }}</strong>
</p>
<h3>{% trans "Transaction history" %}</h3>
{% include "pretixpresale/event/fragment_giftcard_history.html" %}
{% endblock %}

View File

@@ -140,6 +140,9 @@ event_patterns = [
re_path(r'^order/(?P<order>[^/]+)/(?P<secret>[A-Za-z0-9]+)/download/(?P<position>[0-9]+)/(?P<output>[^/]+)$',
pretix.presale.views.order.OrderDownload.as_view(),
name='event.order.download'),
re_path(r'^order/(?P<order>[^/]+)/(?P<secret>[A-Za-z0-9]+)/giftcard/(?P<pk>[0-9]+)/$',
pretix.presale.views.order.OrderGiftCardDetails.as_view(),
name='event.order.giftcard'),
re_path(r'^order/(?P<order>[^/]+)/(?P<secret>[A-Za-z0-9]+)/invoice/(?P<invoice>[0-9]+)$',
pretix.presale.views.order.InvoiceDownload.as_view(),
name='event.invoice.download'),
@@ -150,6 +153,9 @@ event_patterns = [
re_path(r'^ticket/(?P<order>[^/]+)/(?P<position>\d+)/(?P<secret>[A-Za-z0-9]+)/download/(?P<pid>[0-9]+)/(?P<output>[^/]+)$',
pretix.presale.views.order.OrderPositionDownload.as_view(),
name='event.order.position.download'),
re_path(r'^ticket/(?P<order>[^/]+)/(?P<position>\d+)/(?P<secret>[A-Za-z0-9]+)/giftcard/(?P<pk>[0-9]+)/$',
pretix.presale.views.order.OrderPositionGiftCardDetails.as_view(),
name='event.order.position.giftcard'),
re_path(r'^ticket/(?P<order>[^/]+)/(?P<position>\d+)/(?P<secret>[A-Za-z0-9]+)/change$',
pretix.presale.views.order.OrderPositionChange.as_view(),
name='event.order.position.change'),

View File

@@ -57,7 +57,7 @@ from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import gettext, gettext_lazy as _
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import TemplateView, View
from django.views.generic import ListView, TemplateView, View
from pretix.base.models import (
CachedTicket, Checkin, GiftCard, Invoice, Order, OrderPosition, Quota,
@@ -241,7 +241,7 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TicketPageMixin,
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
qs = self.order.positions.prefetch_related('issued_gift_cards').select_related('tax_rule')
qs = self.order.positions.prefetch_related('issued_gift_cards', 'owned_gift_cards').select_related('tax_rule')
if self.request.event.settings.show_checkin_number_user:
qs = qs.annotate(
checkin_count=Subquery(
@@ -1128,6 +1128,53 @@ class OrderDownload(OrderDownloadMixin, EventViewMixin, OrderDetailMixin, AsyncA
return None
@method_decorator(xframe_options_exempt, 'dispatch')
class OrderGiftCardDetails(EventViewMixin, OrderDetailMixin, ListView):
template_name = 'pretixpresale/event/order_giftcard.html'
context_object_name = 'transactions'
paginate_by = 50
@cached_property
def giftcard(self):
return GiftCard.objects.filter(
owner_ticket__order_id=self.order.pk
).get(pk=self.kwargs['pk'])
def get_queryset(self):
return self.giftcard.transactions.order_by('-datetime', '-pk')
def get_context_data(self, **kwargs):
return super().get_context_data(
order=self.order,
giftcard=self.giftcard,
**kwargs,
)
@method_decorator(xframe_options_exempt, 'dispatch')
class OrderPositionGiftCardDetails(EventViewMixin, OrderPositionDetailMixin, ListView):
template_name = 'pretixpresale/event/position_giftcard.html'
context_object_name = 'transactions'
paginate_by = 50
@cached_property
def giftcard(self):
return GiftCard.objects.filter(
Q(owner_ticket_id=self.position.pk) | Q(owner_ticket__addon_to_id=self.position.pk)
).get(pk=self.kwargs['pk'])
def get_queryset(self):
return self.giftcard.transactions.order_by('-datetime', '-pk')
def get_context_data(self, **kwargs):
return super().get_context_data(
order=self.order,
position=self.position,
giftcard=self.giftcard,
**kwargs,
)
@method_decorator(xframe_options_exempt, 'dispatch')
class OrderPositionDownload(OrderDownloadMixin, EventViewMixin, OrderPositionDetailMixin, AsyncAction, View):
task = generate