Improve logging of gift card changes and show logs

This commit is contained in:
Raphael Michel
2020-01-02 17:40:11 +01:00
parent ff98ae3200
commit 76359c859f
4 changed files with 96 additions and 77 deletions
+2
View File
@@ -325,6 +325,8 @@ def pretixcontrol_logentry_display(sender: Event, logentry: LogEntry, **kwargs):
'pretix.device.initialized': _('The device has been initialized.'), 'pretix.device.initialized': _('The device has been initialized.'),
'pretix.device.keyroll': _('The access token of the device has been regenerated.'), 'pretix.device.keyroll': _('The access token of the device has been regenerated.'),
'pretix.device.updated': _('The device has notified the server of an hardware or software update.'), 'pretix.device.updated': _('The device has notified the server of an hardware or software update.'),
'pretix.giftcards.created': _('The gift card has been created.'),
'pretix.giftcards.transaction.manual': _('A manual transaction has been performed.'),
} }
data = json.loads(logentry.data) data = json.loads(logentry.data)
@@ -11,81 +11,95 @@
<span class="label label-warning">{% trans "TEST MODE" %}</span> <span class="label label-warning">{% trans "TEST MODE" %}</span>
{% endif %} {% endif %}
</h1> </h1>
<div class="panel panel-primary items"> <div class="row">
<div class="panel-heading"> <div class="col-md-10 col-xs-12">
<h3 class="panel-title"> <div class="panel panel-primary items">
{% trans "Details" %} <div class="panel-heading">
</h3> <h3 class="panel-title">
</div> {% trans "Details" %}
<div class="panel-body"> </h3>
<dl class="dl-horizontal"> </div>
<dt>{% trans "Gift card code" %}</dt> <div class="panel-body">
<dd>{{ card.secret }}</dd> <dl class="dl-horizontal">
<dt>{% trans "Creation date" %}</dt> <dt>{% trans "Gift card code" %}</dt>
<dd>{{ card.issuance|date:"SHORT_DATETIME_FORMAT" }}</dd> <dd>{{ card.secret }}</dd>
<dt>{% trans "Current value" %}</dt> <dt>{% trans "Creation date" %}</dt>
<dd>{{ card.value|money:card.currency }}</dd> <dd>{{ card.issuance|date:"SHORT_DATETIME_FORMAT" }}</dd>
<dt>{% trans "Currency" %}</dt> <dt>{% trans "Current value" %}</dt>
<dd>{{ card.currency }}</dd> <dd>{{ card.value|money:card.currency }}</dd>
{% if card.issued_in %} <dt>{% trans "Currency" %}</dt>
<dt>{% trans "Issued through sale" %}</dt> <dd>{{ card.currency }}</dd>
<dd> {% if card.issued_in %}
<a href="{% url "control:event.order" event=card.issued_in.order.event.slug organizer=card.issued_in.order.event.organizer.slug code=card.issued_in.order.code %}"> <dt>{% trans "Issued through sale" %}</dt>
{{ card.issued_in.order.full_code }}</a>-{{ card.issued_in.positionid }} <dd>
</dd> <a href="{% url "control:event.order" event=card.issued_in.order.event.slug organizer=card.issued_in.order.event.organizer.slug code=card.issued_in.order.code %}">
{% endif %} {{ card.issued_in.order.full_code }}</a>-{{ card.issued_in.positionid }}
</dl> </dd>
</div>
</div>
<div class="panel panel-default items">
<div class="panel-heading">
<h3 class="panel-title">
{% trans "Transactions" %}
</h3>
</div>
<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 card.transactions.all %}
<tr>
<td>{{ t.datetime|date:"SHORT_DATETIME_FORMAT" }}</td>
<td>
{% if t.order %}
<a href="{% url "control:event.order" event=t.order.event.slug organizer=t.order.event.organizer.slug code=t.order.code %}">
{{ t.order.full_code }}
</a>
{% else %}
<em>{% trans "Manual transaction" %}</em>
{% endif %} {% endif %}
</td> </dl>
<td class="text-right"> </div>
{{ t.value|money:card.currency }} </div>
</td> <div class="panel panel-default items">
</tr> <div class="panel-heading">
{% endfor %} <h3 class="panel-title">
</tbody> {% trans "Transactions" %}
<tfoot> </h3>
<tr> </div>
<td></td> <table class="panel-body table">
<td></td> <thead>
<td class="text-right"> <tr>
<form class="helper-display-inline form-inline" method="post" action=""> <th>{% trans "Date" %}</th>
{% csrf_token %} <th>{% trans "Order" %}</th>
<input type="text" class="form-control input-sm" placeholder="{% trans "Value" %}" name="value"> <th class="text-right">{% trans "Value" %}</th>
<button class="btn btn-primary"> </tr>
<span class="fa fa-plus"></span> </thead>
</button> <tbody>
</form> {% for t in card.transactions.all %}
</td> <tr>
<td>{{ t.datetime|date:"SHORT_DATETIME_FORMAT" }}</td>
<td>
{% if t.order %}
<a href="{% url "control:event.order" event=t.order.event.slug organizer=t.order.event.organizer.slug code=t.order.code %}">
{{ t.order.full_code }}
</a>
{% else %}
<em>{% trans "Manual transaction" %}</em>
{% endif %}
</td>
<td class="text-right">
{{ t.value|money:card.currency }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td class="text-right">
<form class="helper-display-inline form-inline" method="post" action="">
{% csrf_token %}
<input type="text" class="form-control input-sm" placeholder="{% trans "Value" %}" name="value">
<button class="btn btn-primary">
<span class="fa fa-plus"></span>
</button>
</form>
</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
</div>
</div>
<div class="col-md-2 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
{% trans "Gift card history" %}
</h3>
</div>
{% include "pretixcontrol/includes/logs.html" with obj=card %}
</div>
</div>
</div> </div>
{% endblock %} {% endblock %}
+1
View File
@@ -724,6 +724,7 @@ class OrderRefundView(OrderView):
currency=self.request.event.currency, currency=self.request.event.currency,
testmode=self.order.testmode testmode=self.order.testmode
) )
giftcard.log_action('pretix.giftcards.created', user=self.request.user, data={})
refunds.append(OrderRefund( refunds.append(OrderRefund(
order=self.order, order=self.order,
payment=None, payment=None,
+5 -3
View File
@@ -1056,9 +1056,11 @@ class GiftCardCreateView(OrganizerDetailViewMixin, OrganizerPermissionRequiredMi
form.instance.transactions.create( form.instance.transactions.create(
value=form.cleaned_data['value'] value=form.cleaned_data['value']
) )
form.instance.log_action('pretix.giftcards.transaction.manual', user=self.request.user, data={ form.instance.log_action('pretix.giftcards.created', user=self.request.user, data={})
'value': form.cleaned_data['value'] if form.cleaned_data['value']:
}) form.instance.log_action('pretix.giftcards.transaction.manual', user=self.request.user, data={
'value': form.cleaned_data['value']
})
return redirect(reverse( return redirect(reverse(
'control:organizer.giftcard', 'control:organizer.giftcard',
kwargs={ kwargs={