Do not group positions in control view

This commit is contained in:
Raphael Michel
2016-12-21 18:42:14 +01:00
parent 77e917345c
commit 9bf9cc0f9f
3 changed files with 11 additions and 27 deletions

View File

@@ -43,6 +43,7 @@
<div class="panel panel-default items"> <div class="panel panel-default items">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"> <h3 class="panel-title">
#{{ position.positionid }}
<strong>{{ position.item.name }}</strong> <strong>{{ position.item.name }}</strong>
{% if position.variation %} {% if position.variation %}
{{ position.variation }} {{ position.variation }}

View File

@@ -158,8 +158,8 @@
<div class="panel-body"> <div class="panel-body">
{% for line in items.positions %} {% for line in items.positions %}
<div class="row-fluid product-row"> <div class="row-fluid product-row">
<div class="col-md-4 col-xs-6"> <div class="col-md-9 col-xs-6">
{{ line.positionid }} #{{ line.positionid }}
<strong>{{ line.item.name }}</strong> <strong>{{ line.item.name }}</strong>
{% if line.variation %} {% if line.variation %}
{{ line.variation }} {{ line.variation }}
@@ -185,14 +185,8 @@
</dl> </dl>
{% endif %} {% endif %}
</div> </div>
<div class="col-md-2 col-xs-6 count">
{{ line.count }}
</div>
<div class="col-md-3 col-xs-6 price"> <div class="col-md-3 col-xs-6 price">
{{ event.currency }} {{ line.price|floatformat:2 }} <strong>{{ event.currency }} {{ line.price|floatformat:2 }}</strong>
</div>
<div class="col-md-3 col-xs-6 price">
<strong>{{ event.currency }} {{ line.total|floatformat:2 }}</strong>
{% if line.tax_rate %} {% if line.tax_rate %}
<br/> <br/>
<small>{% blocktrans trimmed with rate=line.tax_rate %} <small>{% blocktrans trimmed with rate=line.tax_rate %}

View File

@@ -1,5 +1,4 @@
from datetime import timedelta from datetime import timedelta
from itertools import groupby
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@@ -166,24 +165,14 @@ class OrderDetail(OrderView):
'item__questions', 'answers', 'answers__question' 'item__questions', 'answers', 'answers__question'
) )
# Group items of the same variation
# We do this by list manipulations instead of a GROUP BY query, as
# Django is unable to join related models in a .values() query
def keyfunc(pos):
if (pos.item.admission and self.request.event.settings.attendee_names_asked) \
or pos.item.questions.all():
return pos.id, 0, 0, 0, 0, 0
return 0, pos.item_id, pos.variation_id, pos.price, pos.tax_rate, (pos.voucher_id or 0)
positions = [] positions = []
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc): for p in cartpos:
g = list(g) p.has_questions = (
group = g[0] (p.item.admission and self.request.event.settings.attendee_names_asked) or
group.count = len(g) p.item.questions.all()
group.total = group.count * group.price )
group.has_questions = k[0] != "" p.cache_answers()
group.cache_answers() positions.append(p)
positions.append(group)
return { return {
'positions': positions, 'positions': positions,