Refs #79 -- Toggle between number and money in order overview

This commit is contained in:
Raphael Michel
2015-07-19 13:16:36 +02:00
parent cfd966fe2f
commit ca870e02bd
6 changed files with 94 additions and 51 deletions

View File

@@ -23,5 +23,13 @@ $(function () {
});
});
}
$("#sumtoggle").find("button").click(function () {
$(".table-product-overview .sum").toggle($(this).attr("data-target") === ".sum");
$("#sumtoggle").find("button").not($(this)).removeClass("active");
$(this).addClass("active");
$(".table-product-overview .count").toggle($(this).attr("data-target") === ".count");
});
$('.collapsible').collapse();
});

View File

@@ -12,4 +12,10 @@
th:not(:first-child) {
text-align: right;
}
span.sum {
display: none;
}
}
#sumtoggle {
margin-top: 20px;
}

View File

@@ -1,7 +1,14 @@
{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load order_overview %}
{% block title %}{% trans "Order overview" %}{% endblock %}
{% block content %}
<div class="pull-right">
<div class="btn-group" role="group" id="sumtoggle">
<button type="button" data-target=".count" class="btn btn-default active">Show number</button>
<button type="button" data-target=".sum" class="btn btn-default">Show {{ request.event.currency }}</button>
</div>
</div>
<h1>{% trans "Order overview" %}</h1>
<div class="table-responsive">
<table class="table table-condensed table-hover table-product-overview">
@@ -20,31 +27,31 @@
{% if tup.0 %}
<tr class="category">
<th>{{ tup.0.name }}</th>
<th>{{ tup.0.num_total }}</th>
<th>{{ tup.0.num_pending }}</th>
<th>{{ tup.0.num_cancelled }}</th>
<th>{{ tup.0.num_refunded }}</th>
<th>{{ tup.0.num_paid }}</th>
<th>{{ tup.0.num_total|togglesum }}</th>
<th>{{ tup.0.num_pending|togglesum }}</th>
<th>{{ tup.0.num_cancelled|togglesum }}</th>
<th>{{ tup.0.num_refunded|togglesum }}</th>
<th>{{ tup.0.num_paid|togglesum }}</th>
</tr>
{% endif %}
{% for item in tup.1 %}
<tr class="item {% if tup.0 %}categorized{% endif %}">
<td>{{ item.name }}</td>
<td>{{ item.num_total }}</td>
<td>{{ item.num_pending }}</td>
<td>{{ item.num_cancelled }}</td>
<td>{{ item.num_refunded }}</td>
<td>{{ item.num_paid }}</td>
<td>{{ item.num_total|togglesum }}</td>
<td>{{ item.num_pending|togglesum }}</td>
<td>{{ item.num_cancelled|togglesum }}</td>
<td>{{ item.num_refunded|togglesum }}</td>
<td>{{ item.num_paid|togglesum }}</td>
</tr>
{% if item.has_variations %}
{% for var in item.all_variations %}
<tr class="variation {% if tup.0 %}categorized{% endif %}">
<td>{{ var }}</td>
<td>{{ var.num_total }}</td>
<td>{{ var.num_pending }}</td>
<td>{{ var.num_cancelled }}</td>
<td>{{ var.num_refunded }}</td>
<td>{{ var.num_paid }}</td>
<td>{{ var.num_total|togglesum }}</td>
<td>{{ var.num_pending|togglesum }}</td>
<td>{{ var.num_cancelled|togglesum }}</td>
<td>{{ var.num_refunded|togglesum }}</td>
<td>{{ var.num_paid|togglesum }}</td>
</tr>
{% endfor %}
{% endif %}
@@ -54,11 +61,11 @@
<tfoot>
<tr class="total">
<th>{% trans "Total" %}</th>
<th>{{ total.num_total }}</th>
<th>{{ total.num_pending }}</th>
<th>{{ total.num_cancelled }}</th>
<th>{{ total.num_refunded }}</th>
<th>{{ total.num_paid }}</th>
<th>{{ total.num_total|togglesum }}</th>
<th>{{ total.num_pending|togglesum }}</th>
<th>{{ total.num_cancelled|togglesum }}</th>
<th>{{ total.num_refunded|togglesum }}</th>
<th>{{ total.num_paid|togglesum }}</th>
</tr>
</tfoot>
</table>

View File

@@ -0,0 +1,18 @@
from django import template
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils import formats
register = template.Library()
@register.filter(name='togglesum', needs_autoescape=True)
def cut(value, autoescape=True):
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
return mark_safe('<span class="count">{0}</span><span class="sum">{1}</span>'.format(
esc(value[0]), esc(formats.localize(value[1]))
))

View File

@@ -1,7 +1,7 @@
from itertools import groupby
from django.contrib import messages
from django.db.models import Count, Q
from django.db.models import Count, Q, Sum
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
@@ -202,6 +202,10 @@ class OrderExtend(OrderView):
data=self.request.POST if self.request.method == "POST" else None)
def tuplesum(tuples):
return tuple(map(sum, zip(*list(tuples))))
class OverView(EventPermissionRequiredMixin, TemplateView):
template_name = 'pretixcontrol/orders/overview.html'
permission = 'can_view_orders'
@@ -215,39 +219,39 @@ class OverView(EventPermissionRequiredMixin, TemplateView):
).order_by('category__position', 'category_id', 'name')
num_total = {
(p['item'], p['variation']): p['cnt']
(p['item'], p['variation']): (p['cnt'], p['price'])
for p in
OrderPosition.objects.current.filter(order__event=self.request.event).values('item', 'variation').annotate(
cnt=Count('id'))
cnt=Count('id'), price=Sum('price'))
}
num_cancelled = {
(p['item'], p['variation']): p['cnt']
(p['item'], p['variation']): (p['cnt'], p['price'])
for p in (OrderPosition.objects.current
.filter(order__event=self.request.event, order__status=Order.STATUS_CANCELLED)
.values('item', 'variation')
.annotate(cnt=Count('id')))
.annotate(cnt=Count('id'), price=Sum('price')))
}
num_refunded = {
(p['item'], p['variation']): p['cnt']
(p['item'], p['variation']): (p['cnt'], p['price'])
for p in (OrderPosition.objects.current
.filter(order__event=self.request.event, order__status=Order.STATUS_REFUNDED)
.values('item', 'variation')
.annotate(cnt=Count('id')))
.annotate(cnt=Count('id'), price=Sum('price')))
}
num_pending = {
(p['item'], p['variation']): p['cnt']
(p['item'], p['variation']): (p['cnt'], p['price'])
for p in (OrderPosition.objects.current
.filter(order__event=self.request.event,
order__status__in=(Order.STATUS_PENDING, Order.STATUS_EXPIRED))
.values('item', 'variation')
.annotate(cnt=Count('id')))
.annotate(cnt=Count('id'), price=Sum('price')))
}
num_paid = {
(p['item'], p['variation']): p['cnt']
(p['item'], p['variation']): (p['cnt'], p['price'])
for p in (OrderPosition.objects.current
.filter(order__event=self.request.event, order__status=Order.STATUS_PAID)
.values('item', 'variation')
.annotate(cnt=Count('id')))
.annotate(cnt=Count('id'), price=Sum('price')))
}
for item in items:
@@ -255,18 +259,18 @@ class OverView(EventPermissionRequiredMixin, TemplateView):
key=lambda vd: vd.ordered_values())
for var in item.all_variations:
variid = var['variation'].identity if 'variation' in var else None
var.num_total = num_total.get((item.identity, variid), 0)
var.num_pending = num_pending.get((item.identity, variid), 0)
var.num_cancelled = num_cancelled.get((item.identity, variid), 0)
var.num_refunded = num_refunded.get((item.identity, variid), 0)
var.num_paid = num_paid.get((item.identity, variid), 0)
var.num_total = num_total.get((item.identity, variid), (0, 0))
var.num_pending = num_pending.get((item.identity, variid), (0, 0))
var.num_cancelled = num_cancelled.get((item.identity, variid), (0, 0))
var.num_refunded = num_refunded.get((item.identity, variid), (0, 0))
var.num_paid = num_paid.get((item.identity, variid), (0, 0))
item.has_variations = (len(item.all_variations) != 1
or not item.all_variations[0].empty())
item.num_total = sum(var.num_total for var in item.all_variations)
item.num_pending = sum(var.num_pending for var in item.all_variations)
item.num_cancelled = sum(var.num_cancelled for var in item.all_variations)
item.num_refunded = sum(var.num_refunded for var in item.all_variations)
item.num_paid = sum(var.num_paid for var in item.all_variations)
item.num_total = tuplesum(var.num_total for var in item.all_variations)
item.num_pending = tuplesum(var.num_pending for var in item.all_variations)
item.num_cancelled = tuplesum(var.num_cancelled for var in item.all_variations)
item.num_refunded = tuplesum(var.num_refunded for var in item.all_variations)
item.num_paid = tuplesum(var.num_paid for var in item.all_variations)
nonecat = ItemCategory(name=_('Uncategorized'))
# Regroup those by category
@@ -281,18 +285,18 @@ class OverView(EventPermissionRequiredMixin, TemplateView):
key=lambda group: (group[0].position, group[0].identity) if group[0] is not None else (0, "")
)
for c in ctx['items_by_category']:
c[0].num_total = sum(item.num_total for item in c[1])
c[0].num_pending = sum(item.num_pending for item in c[1])
c[0].num_cancelled = sum(item.num_cancelled for item in c[1])
c[0].num_refunded = sum(item.num_refunded for item in c[1])
c[0].num_paid = sum(item.num_paid for item in c[1])
c[0].num_total = tuplesum(item.num_total for item in c[1])
c[0].num_pending = tuplesum(item.num_pending for item in c[1])
c[0].num_cancelled = tuplesum(item.num_cancelled for item in c[1])
c[0].num_refunded = tuplesum(item.num_refunded for item in c[1])
c[0].num_paid = tuplesum(item.num_paid for item in c[1])
ctx['total'] = {
'num_total': sum(c.num_total for c, i in ctx['items_by_category']),
'num_pending': sum(c.num_pending for c, i in ctx['items_by_category']),
'num_cancelled': sum(c.num_cancelled for c, i in ctx['items_by_category']),
'num_refunded': sum(c.num_refunded for c, i in ctx['items_by_category']),
'num_paid': sum(c.num_paid for c, i in ctx['items_by_category'])
'num_total': tuplesum(c.num_total for c, i in ctx['items_by_category']),
'num_pending': tuplesum(c.num_pending for c, i in ctx['items_by_category']),
'num_cancelled': tuplesum(c.num_cancelled for c, i in ctx['items_by_category']),
'num_refunded': tuplesum(c.num_refunded for c, i in ctx['items_by_category']),
'num_paid': tuplesum(c.num_paid for c, i in ctx['items_by_category'])
}
return ctx