Own column for unapproved orders in order overview

This commit is contained in:
Raphael Michel
2020-11-01 15:00:54 +01:00
parent da149682aa
commit 7a98f3fa89
4 changed files with 64 additions and 13 deletions
+3
View File
@@ -127,6 +127,7 @@ def order_overview(
order__event=event order__event=event
).annotate( ).annotate(
status=Case( status=Case(
When(order__status='n', order__require_approval=True, then=Value('unapproved')),
When(canceled=True, then=Value('c')), When(canceled=True, then=Value('c')),
default=F('order__status') default=F('order__status')
) )
@@ -135,6 +136,7 @@ def order_overview(
).annotate(cnt=Count('id'), price=Sum('price'), tax_value=Sum('tax_value')).order_by() ).annotate(cnt=Count('id'), price=Sum('price'), tax_value=Sum('tax_value')).order_by()
states = { states = {
'unapproved': 'unapproved',
'canceled': Order.STATUS_CANCELED, 'canceled': Order.STATUS_CANCELED,
'paid': Order.STATUS_PAID, 'paid': Order.STATUS_PAID,
'pending': Order.STATUS_PENDING, 'pending': Order.STATUS_PENDING,
@@ -198,6 +200,7 @@ def order_overview(
order__event=event order__event=event
).annotate( ).annotate(
status=Case( status=Case(
When(order__status='n', order__require_approval=True, then=Value('unapproved')),
When(canceled=True, then=Value('c')), When(canceled=True, then=Value('c')),
default=F('order__status') default=F('order__status')
) )
@@ -12,7 +12,14 @@
<button type="button" data-target=".sum-net" class="btn btn-default">{% trans "Revenue (net)" %}</button> <button type="button" data-target=".sum-net" class="btn btn-default">{% trans "Revenue (net)" %}</button>
</div> </div>
</div> </div>
<h1>{% trans "Order overview" %}</h1> <h1>
{% trans "Order overview" %}
<a href="{% url "control:event.orders.export" event=request.event.slug organizer=request.event.organizer.slug %}?identifier=overview"
class="btn btn-default" target="_blank">
<span class="fa fa-download"></span>
{% trans "PDF" %}
</a>
</h1>
<div class="row filter-form"> <div class="row filter-form">
<form class="" action="" method="get"> <form class="" action="" method="get">
{% if request.event.has_subevents %} {% if request.event.has_subevents %}
@@ -58,12 +65,14 @@
<th>{% trans "Product" %}</th> <th>{% trans "Product" %}</th>
<th>{% trans "Canceled" %}¹</th> <th>{% trans "Canceled" %}¹</th>
<th>{% trans "Expired" %}</th> <th>{% trans "Expired" %}</th>
<th>{% trans "Approval pending" %}</th>
<th colspan="3" class="text-center">{% trans "Purchased" %}</th> <th colspan="3" class="text-center">{% trans "Purchased" %}</th>
</tr> </tr>
<tr> <tr>
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
<th></th>
<th>{% trans "Pending" %}</th> <th>{% trans "Pending" %}</th>
<th>{% trans "Paid" %}</th> <th>{% trans "Paid" %}</th>
<th>{% trans "Total" %}</th> <th>{% trans "Total" %}</th>
@@ -76,6 +85,7 @@
<th>{{ tup.0 }}</th> <th>{{ tup.0 }}</th>
<th>{{ tup.0.num.canceled|togglesum:request.event.currency }}</th> <th>{{ tup.0.num.canceled|togglesum:request.event.currency }}</th>
<th>{{ tup.0.num.expired|togglesum:request.event.currency }}</th> <th>{{ tup.0.num.expired|togglesum:request.event.currency }}</th>
<th>{{ tup.0.num.unapproved|togglesum:request.event.currency }}</th>
<th>{{ tup.0.num.pending|togglesum:request.event.currency }}</th> <th>{{ tup.0.num.pending|togglesum:request.event.currency }}</th>
<th>{{ tup.0.num.paid|togglesum:request.event.currency }}</th> <th>{{ tup.0.num.paid|togglesum:request.event.currency }}</th>
<th>{{ tup.0.num.total|togglesum:request.event.currency }}</th> <th>{{ tup.0.num.total|togglesum:request.event.currency }}</th>
@@ -94,6 +104,11 @@
{{ item.num.expired|togglesum:request.event.currency }} {{ item.num.expired|togglesum:request.event.currency }}
</a> </a>
</td> </td>
<td>
<a href="{{ listurl }}?item={{ item.id }}&amp;status=pa&amp;provider={{ item.provider }}">
{{ item.num.unapproved|togglesum:request.event.currency }}
</a>
</td>
<td> <td>
<a href="{{ listurl }}?item={{ item.id }}&amp;status=n&amp;provider={{ item.provider }}"> <a href="{{ listurl }}?item={{ item.id }}&amp;status=n&amp;provider={{ item.provider }}">
{{ item.num.pending|togglesum:request.event.currency }} {{ item.num.pending|togglesum:request.event.currency }}
@@ -122,6 +137,11 @@
{{ var.num.expired|togglesum:request.event.currency }} {{ var.num.expired|togglesum:request.event.currency }}
</a> </a>
</td> </td>
<td>
<a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=pa&amp;provider={{ item.provider }}">
{{ var.num.unapproved|togglesum:request.event.currency }}
</a>
</td>
<td> <td>
<a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=n&amp;provider={{ item.provider }}"> <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=n&amp;provider={{ item.provider }}">
{{ var.num.pending|togglesum:request.event.currency }} {{ var.num.pending|togglesum:request.event.currency }}
@@ -146,6 +166,7 @@
<th>{% trans "Total" %}</th> <th>{% trans "Total" %}</th>
<th>{{ total.num.canceled|togglesum:request.event.currency }}</th> <th>{{ total.num.canceled|togglesum:request.event.currency }}</th>
<th>{{ total.num.expired|togglesum:request.event.currency }}</th> <th>{{ total.num.expired|togglesum:request.event.currency }}</th>
<th>{{ total.num.unapproved|togglesum:request.event.currency }}</th>
<th>{{ total.num.pending|togglesum:request.event.currency }}</th> <th>{{ total.num.pending|togglesum:request.event.currency }}</th>
<th>{{ total.num.paid|togglesum:request.event.currency }}</th> <th>{{ total.num.paid|togglesum:request.event.currency }}</th>
<th>{{ total.num.total|togglesum:request.event.currency }}</th> <th>{{ total.num.total|togglesum:request.event.currency }}</th>
+37 -10
View File
@@ -1,3 +1,4 @@
import copy
import tempfile import tempfile
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
from decimal import Decimal from decimal import Decimal
@@ -14,6 +15,7 @@ from django.utils.formats import date_format, localize
from django.utils.timezone import get_current_timezone, now from django.utils.timezone import get_current_timezone, now
from django.utils.translation import gettext as _, gettext_lazy, pgettext from django.utils.translation import gettext as _, gettext_lazy, pgettext
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER
from reportlab.platypus import PageBreak from reportlab.platypus import PageBreak
from pretix.base.decimal import round_decimal from pretix.base.decimal import round_decimal
@@ -183,27 +185,44 @@ class OverviewReport(Report):
headlinestyle.fontSize = 15 headlinestyle.fontSize = 15
headlinestyle.fontName = 'OpenSansBd' headlinestyle.fontName = 'OpenSansBd'
colwidths = [ colwidths = [
a * doc.width for a in (.33, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075, 0.05, .075) a * doc.width for a in (
1 - (0.05 + 0.075) * 6,
0.05, .075,
0.05, .075,
0.05, .075,
0.05, .075,
0.05, .075,
0.05, .075
)
] ]
tstyledata = [ tstyledata = [
('SPAN', (1, 0), (2, 0)), ('SPAN', (1, 0), (2, 0)),
('SPAN', (3, 0), (4, 0)), ('SPAN', (3, 0), (4, 0)),
('SPAN', (5, 0), (-1, 0)), ('SPAN', (5, 0), (6, 1)),
('SPAN', (5, 1), (6, 1)), ('SPAN', (7, 0), (-1, 0)),
('SPAN', (7, 1), (8, 1)), ('SPAN', (7, 1), (8, 1)),
('SPAN', (9, 1), (10, 1)), ('SPAN', (9, 1), (10, 1)),
('SPAN', (11, 1), (12, 1)),
('ALIGN', (0, 0), (-1, 1), 'CENTER'), ('ALIGN', (0, 0), (-1, 1), 'CENTER'),
('ALIGN', (1, 2), (-1, -1), 'RIGHT'), ('ALIGN', (1, 2), (-1, -1), 'RIGHT'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'), ('FONTNAME', (0, 0), (-1, 1), 'OpenSansBd'),
('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'), ('FONTNAME', (0, -1), (-1, -1), 'OpenSansBd'),
('FONTSIZE', (0, 0), (-1, -1), 9), ('FONTSIZE', (0, 0), (-1, -1), 8),
('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey), ('LINEBEFORE', (1, 0), (1, -1), 1, colors.lightgrey),
('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey), ('LINEBEFORE', (3, 0), (3, -1), 1, colors.lightgrey),
('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey), ('LINEBEFORE', (5, 0), (5, -1), 1, colors.lightgrey),
('LINEBEFORE', (7, 1), (7, -1), 1, colors.lightgrey), ('LINEBEFORE', (7, 0), (7, -1), 1, colors.lightgrey),
('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey), ('LINEBEFORE', (9, 1), (9, -1), 1, colors.lightgrey),
('LINEBEFORE', (11, 1), (11, -1), 1, colors.lightgrey),
] ]
tstyle = copy.copy(self.get_style())
tstyle.fontSize = 8
tstyle_bold = copy.copy(tstyle)
tstyle_bold.fontSize = 8
tstyle_bold.fontName = 'OpenSansBd'
tstyle_th = copy.copy(tstyle_bold)
tstyle_th.alignment = TA_CENTER
story = [ story = [
Paragraph(_('Orders by product') + ' ' + (_('(excl. taxes)') if net else _('(incl. taxes)')), headlinestyle), Paragraph(_('Orders by product') + ' ' + (_('(excl. taxes)') if net else _('(incl. taxes)')), headlinestyle),
Spacer(1, 5 * mm) Spacer(1, 5 * mm)
@@ -227,11 +246,18 @@ class OverviewReport(Report):
story.append(Spacer(1, 5 * mm)) story.append(Spacer(1, 5 * mm))
tdata = [ tdata = [
[ [
_('Product'), _('Canceled'), '', _('Expired'), '', _('Purchased'), _('Product'),
Paragraph(_('Canceled'), tstyle_th),
'',
Paragraph(_('Expired'), tstyle_th),
'',
Paragraph(_('Approval pending'), tstyle_th),
'',
Paragraph(_('Purchased'), tstyle_th),
'', '', '', '', '' '', '', '', '', ''
], ],
[ [
'', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), '' '', '', '', '', '', '', '', _('Pending'), '', _('Paid'), '', _('Total'), ''
], ],
[ [
'', '',
@@ -240,6 +266,7 @@ class OverviewReport(Report):
_('#'), self.event.currency, _('#'), self.event.currency,
_('#'), self.event.currency, _('#'), self.event.currency,
_('#'), self.event.currency, _('#'), self.event.currency,
_('#'), self.event.currency,
], ],
] ]
@@ -255,6 +282,7 @@ class OverviewReport(Report):
states = ( states = (
('canceled', Order.STATUS_CANCELED), ('canceled', Order.STATUS_CANCELED),
('expired', Order.STATUS_EXPIRED), ('expired', Order.STATUS_EXPIRED),
('unapproved', 'unapproved'),
('pending', Order.STATUS_PENDING), ('pending', Order.STATUS_PENDING),
('paid', Order.STATUS_PAID), ('paid', Order.STATUS_PAID),
('total', None), ('total', None),
@@ -262,9 +290,8 @@ class OverviewReport(Report):
for tup in items_by_category: for tup in items_by_category:
if tup[0]: if tup[0]:
tstyledata.append(('FONTNAME', (0, len(tdata)), (-1, len(tdata)), 'OpenSansBd'))
tdata.append([ tdata.append([
tup[0].name, Paragraph(tup[0].name, tstyle_bold)
]) ])
for l, s in states: for l, s in states:
tdata[-1].append(str(tup[0].num[l][0])) tdata[-1].append(str(tup[0].num[l][0]))
@@ -279,7 +306,7 @@ class OverviewReport(Report):
if item.has_variations: if item.has_variations:
for var in item.all_variations: for var in item.all_variations:
tdata.append([ tdata.append([
" " + str(var), Paragraph(" " + str(var), tstyle)
]) ])
for l, s in states: for l, s in states:
tdata[-1].append(str(var.num[l][0])) tdata[-1].append(str(var.num[l][0]))
@@ -14,7 +14,7 @@
padding-left: 40px; padding-left: 40px;
} }
td:not(:first-child), td:not(:first-child),
th:not(:first-child):not(.text-center) { th:not(:first-child) {
border-left: 1px solid #ddd; border-left: 1px solid #ddd;
padding-right: 10px !important; padding-right: 10px !important;
padding-left: 10px !important; padding-left: 10px !important;
@@ -34,7 +34,7 @@
.table-product-overview { .table-product-overview {
td:not(:first-child), td:not(:first-child),
th:not(:first-child):not(.text-center) { th:not(:first-child):not(.text-center) {
width: 150px; width: 120px;
} }
} }
} }