Order changing permissions, list of ordered items

This commit is contained in:
Raphael Michel
2015-03-20 17:29:47 +01:00
parent dbc3dff905
commit 244ad04520
8 changed files with 220 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.core.validators
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0020_auto_20150319_1044'),
]
operations = [
migrations.AddField(
model_name='eventpermission',
name='can_change_orders',
field=models.BooleanField(default=True, verbose_name='Can change orders'),
),
migrations.AddField(
model_name='eventpermission',
name='can_view_orders',
field=models.BooleanField(default=True, verbose_name='Can view orders'),
),
migrations.AlterField(
model_name='event',
name='slug',
field=models.SlugField(verbose_name='Slug', validators=[django.core.validators.RegexValidator(message='The slug may only contain letters, numbers, dots and dashes.', regex='^[a-zA-Z0-9.-]+$')], help_text='Should be short, only contain lowercase letters and numbers, and must be unique among your events. This is being used in addresses and bank transfer references.'),
),
]

View File

@@ -535,6 +535,10 @@ class EventPermission(Versionable):
:type can_change_settings: bool
:param can_change_items: If ``True``, the user can change and add items and related objects for this event.
:type can_change_items: bool
:param can_view_orders: If ``True``, the user can inspect details of all orders.
:type can_view_orders: bool
:param can_change_orders: If ``True``, the user can change details of orders
:type can_change_orders: bool
"""
event = VersionedForeignKey(Event)
@@ -547,6 +551,14 @@ class EventPermission(Versionable):
default=True,
verbose_name=_("Can change product settings")
)
can_view_orders = models.BooleanField(
default=True,
verbose_name=_("Can view orders")
)
can_change_orders = models.BooleanField(
default=True,
verbose_name=_("Can change orders")
)
class Meta:
verbose_name = _("Event permission")

View File

@@ -18,4 +18,32 @@ nav.navbar {
.nav-pills {
margin-bottom: 10px;
}
}
.product-row {
padding: 10px 0;
.count form {
display: inline;
}
.price, .count {
text-align: right;
}
.price small,
.availability-box small {
display: block;
line-height: 1;
}
&.total {
border-top: 1px solid @table-border-color;
}
dl {
padding-left: 20px;
margin-bottom: 0;
dd {
padding-left: 20px;
}
}
}

View File

@@ -76,7 +76,7 @@
</li>
<li>
<a href="{% url 'control:event.orders' organizer=request.event.organizer.slug event=request.event.slug %}"
{% if "event.orders" in url_name %}class="active"{% endif %}>
{% if "event.order" in url_name %}class="active"{% endif %}>
<i class="fa fa-shopping-cart fa-fw"></i>
{% trans "Orders" %}
</a>

View File

@@ -0,0 +1,81 @@
{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% block title %}
{% blocktrans trimmed with code=order.code %}
Order details: {{ code }}
{% endblocktrans %}
{% endblock %}
{% block content %}
<h1>
{% blocktrans trimmed with code=order.code %}
Order details: {{ code }}
{% endblocktrans %}
</h1>
<div class="panel panel-primary items">
<div class="panel-heading">
<h3 class="panel-title">
{% trans "Ordered items" %}
</h3>
</div>
<div class="panel-body">
{% for line in items.positions %}
<div class="row-fluid product-row">
<div class="col-md-4 col-xs-6">
<strong>{{ line.item }}</strong>
{% if line.variation %}
{{ line.variation }}
{% endif %}
{% if line.has_questions %}
<dl>
{% if line.item.admission and event.settings.attendee_names_asked == 'True' %}
<dt>{% trans "Attendee name" %}</dt>
<dd>{% if line.attendee_name %}{{ line.attendee_name }}{% else %}<em>{% trans "not answered" %}</em>{% endif %}</dd>
{% endif %}
{% for q in line.questions %}
<dt>{{ q.question }}</dt>
<dd>{% if q.answer %}{{ q.answer }}{% else %}<em>{% trans "not answered" %}</em>{% endif %}</dd>
{% endfor %}
</dl>
{% endif %}
</div>
<div class="col-md-3 col-xs-6 price">
{{ event.currency }} {{ line.price|floatformat:2 }}
</div>
<div class="col-md-2 col-xs-6 count">
{{ line.count }}
</div>
<div class="col-md-3 col-xs-6 price">
<strong>{{ event.currency }} {{ line.total|floatformat:2 }}</strong>
{% if line.item.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=line.item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
</div>
<div class="clearfix"></div>
</div>
{% endfor %}
{% if items.payment_fee %}
{# TODO: Tax rate? #}
<div class="row-fluid product-row">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Payment method fee" %}</strong>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
<strong>{{ event.currency }} {{ items.payment_fee|floatformat:2 }}</strong>
</div>
<div class="clearfix"></div>
</div>
{% endif %}
<div class="row-fluid product-row total">
<div class="col-md-4 col-xs-6">
<strong>{% trans "Total" %}</strong>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
<strong>{{ event.currency }} {{ items.total|floatformat:2 }}</strong>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -16,7 +16,9 @@
<tbody>
{% for o in orders %}
<tr>
<td><strong><a href="">{{ o.code }}</a></strong></td>
<td><strong><a
href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=o.code%}"
>{{ o.code }}</a></strong></td>
<td>{{ o.user.get_short_name }}</td>
<td>{{ o.total|floatformat:2 }} {{ request.event.currency }}</td>
<td>{{ o.datetime|date }}</td>

View File

@@ -46,6 +46,7 @@ urlpatterns = [
url(r'^quotas/(?P<quota>[0-9a-f-]+)/delete$', item.QuotaDelete.as_view(),
name='event.items.quotas.delete'),
url(r'^quotas/add$', item.QuotaCreate.as_view(), name='event.items.quotas.add'),
url(r'^orders/(?P<code>[0-9A-Z]+)/$', orders.OrderDetail.as_view(), name='event.order'),
url(r'^orders/$', orders.OrderList.as_view(), name='event.orders'),
])),
]

View File

@@ -1,15 +1,76 @@
from django.views.generic import ListView
from itertools import groupby
from django.db.models import Q
from django.views.generic import ListView, DetailView
from pretix.base.models import Order
from pretix.control.permissions import EventPermissionRequiredMixin
class OrderList(ListView):
class OrderList(EventPermissionRequiredMixin, ListView):
model = Order
context_object_name = 'orders'
template_name = 'pretixcontrol/orders/index.html'
paginate_by = 30
permission = 'can_view_orders'
def get_queryset(self):
return Order.objects.current.filter(
event=self.request.event
).select_related("user")
class OrderDetail(EventPermissionRequiredMixin, DetailView):
model = Order
context_object_name = 'order'
template_name = 'pretixcontrol/order/index.html'
permission = 'can_view_orders'
def get_object(self, queryset=None):
return Order.objects.current.get(
event=self.request.event,
code=self.kwargs['code'].upper()
)
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['items'] = self.get_items()
ctx['event'] = self.request.event
return ctx
def get_items(self):
queryset = self.object.positions.all()
cartpos = queryset.order_by(
'item', 'variation'
).select_related(
'item', 'variation'
).prefetch_related(
'variation__values', 'variation__values__prop', 'item__questions',
'answers'
)
# 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 == 'True')
or pos.item.questions.all()):
return pos.id, "", "", ""
return "", pos.item_id, pos.variation_id, pos.price
positions = []
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):
g = list(g)
group = g[0]
group.count = len(g)
group.total = group.count * group.price
group.has_questions = k[0] != ""
group.cache_answers()
positions.append(group)
return {
'positions': positions,
'raw': cartpos,
'total': self.object.total,
'payment_fee': self.object.payment_fee,
}