Improve visual transaction table

This commit is contained in:
Raphael Michel
2021-10-18 18:34:52 +02:00
parent c8cdb2b311
commit 846527546a
3 changed files with 39 additions and 6 deletions

View File

@@ -18,10 +18,11 @@
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "Product" %}</th>
<th class="text-right flip">{% trans "Quantity" %}</th>
<th class="text-right flip">{% trans "Tax rate" %}</th>
<th class="text-right flip">{% trans "Tax value" %}</th>
<th class="text-right flip">{% trans "Price" %}</th>
<th class="text-right flip">{% trans "Quantity" %}</th>
<th class="text-right flip">{% trans "Single price" %}</th>
<th class="text-right flip">{% trans "Total tax value" %}</th>
<th class="text-right flip">{% trans "Total price" %}</th>
</tr>
</thead>
<tbody>
@@ -50,12 +51,31 @@
<br>{{ t.subevent }}
{% endif %}
</td>
<td class="text-right flip">{{ t.count }} &times;</td>
<td class="text-right flip">{{ t.tax_rate }} %</td>
<td class="text-right flip">{{ t.tax_value|money:request.event.currency }}</td>
<td class="text-right flip">{{ t.count }} &times;</td>
<td class="text-right flip">{{ t.price|money:request.event.currency }}</td>
<td class="text-right flip">{{ t.full_tax_value|money:request.event.currency }}</td>
<td class="text-right flip">{{ t.full_price|money:request.event.currency }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="{% if t.count < 0 %}text-danger{% endif %}">
<td>
<strong>{% trans "Sum" %}</strong>
</td>
<td>
</td>
<td></td>
<td class="text-right flip">
<strong>
{{ sums.count }}
</strong>
</td>
<td></td>
<td class="text-right flip"><strong>{{ sums.full_tax_value|money:request.event.currency }}</strong></td>
<td class="text-right flip"><strong>{{ sums.full_price|money:request.event.currency }}</strong></td>
</tr>
</tfoot>
</table>
{% endblock %}

View File

@@ -50,7 +50,7 @@ from django.core.exceptions import ValidationError
from django.core.files import File
from django.db import transaction
from django.db.models import (
Count, Exists, IntegerField, OuterRef, Prefetch, ProtectedError, Q,
Count, Exists, F, IntegerField, OuterRef, Prefetch, ProtectedError, Q,
Subquery, Sum,
)
from django.forms import formset_factory
@@ -410,6 +410,11 @@ class OrderTransactions(OrderView):
ctx['transactions'] = self.order.transactions.select_related(
'item', 'variation', 'subevent'
).order_by('datetime')
ctx['sums'] = self.order.transactions.aggregate(
count=Sum('count'),
full_price=Sum(F('count') * F('price')),
full_tax_value=Sum(F('count') * F('tax_value')),
)
return ctx