add backoffice pages for merchandise orders and what merchandise to order

This commit is contained in:
Stephan Telling 2018-08-01 11:50:16 +02:00
parent e2ef635abc
commit e04038e4a0
No known key found for this signature in database
GPG Key ID: E2A0AE38ABC88337
5 changed files with 151 additions and 0 deletions

View File

@ -34,6 +34,14 @@
<h4 class="list-group-item-heading">Manage Proposals</h4>
<p class="list-group-item-text">Use this view to manage SpeakerProposals and EventProposals</p>
</a>
<a href="{% url 'backoffice:merchandise_orders' camp_slug=camp.slug %}" class="list-group-item">
<h4 class="list-group-item-heading">Merchandise Orders</h4>
<p class="list-group-item-text">Use this view to look at Merchandise Orders</p>
</a>
<a href="{% url 'backoffice:merchandise_to_order' camp_slug=camp.slug %}" class="list-group-item">
<h4 class="list-group-item-heading">Merchandise To Order</h4>
<p class="list-group-item-text">Use this view to generate a list of merchandise that needs to be ordered</p>
</a>
</div>
</div>

View File

@ -0,0 +1,44 @@
{% extends 'base.html' %}
{% load commonmark %}
{% load static from staticfiles %}
{% load imageutils %}
{% block extra_head %}
<script src="{% static "js/jquery.dataTables.min.js" %}"></script>
<link rel="stylesheet" href="{% static 'css/jquery.dataTables.min.css' %}">
{% endblock extra_head %}
{% block content %}
<div class="row">
<h2>Merchandise To Order</h2>
<div class="lead">
This is a list of merchandise to order from our supplier
</div>
<div>
This table shows all different merchandise that needs to be ordered
</div>
</div>
<br>
<div class="row">
<table class="table table-hover">
<thead>
<tr>
<th>Merchandise Type</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
{% for key, val in merchandise.items %}
<tr>
<td>{{ key }}</td>
<td>{{ val }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
$(document).ready(function(){
$('.table').DataTable();
});
</script>
{% endblock content %}

View File

@ -0,0 +1,51 @@
{% extends 'base.html' %}
{% load commonmark %}
{% load static from staticfiles %}
{% load imageutils %}
{% block extra_head %}
<script src="{% static "js/jquery.dataTables.min.js" %}"></script>
<link rel="stylesheet" href="{% static 'css/jquery.dataTables.min.css' %}">
{% endblock extra_head %}
{% block content %}
<div class="row">
<h2>Merchandise Orders</h2>
<div class="lead">
Use this view to look at merchandise orders. </div>
<div>
This table shows all OrderProductRelations which are Merchandise (not including handed out, unpaid, cancelled and refunded orders). The table is initally sorted by order ID but the sorting can be changed by clicking the column headlines (if javascript is enabled).
</div>
</div>
<br>
<div class="row">
<table class="table table-hover">
<thead>
<tr>
<th>Order</th>
<th>User</th>
<th>Email</th>
<th>OPR Id</th>
<th>Product</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
{% for productrel in orderproductrelation_list %}
<tr>
<td><a href="/admin/shop/order/{{ productrel.order.id }}/change/">Order #{{ productrel.order.id }}</a></td>
<td>{{ productrel.order.user }}</td>
<td>{{ productrel.order.user.email }}</td>
<td>{{ productrel.id }}</td>
<td>{{ productrel.product.name }}</td>
<td>{{ productrel.quantity }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
$(document).ready(function(){
$('.table').DataTable();
});
</script>
{% endblock content %}

View File

@ -10,6 +10,8 @@ urlpatterns = [
path('badge_handout/', BadgeHandoutView.as_view(), name='badge_handout'),
path('ticket_checkin/', TicketCheckinView.as_view(), name='ticket_checkin'),
path('public_credit_names/', ApproveNamesView.as_view(), name='public_credit_names'),
path('merchandise_orders/', MerchandiseOrdersView.as_view(), name='merchandise_orders'),
path('merchandise_to_order/', MerchandiseToOrderView.as_view(), name='merchandise_to_order'),
path('manage_proposals/', include([
path('', ManageProposalsView.as_view(), name='manage_proposals'),
path('speakers/<uuid:pk>/', SpeakerProposalManageView.as_view(), name='speakerproposal_manage'),

View File

@ -1,5 +1,6 @@
import logging
from itertools import chain
from datetime import datetime
from django.views.generic import TemplateView, ListView
from django.views.generic.edit import UpdateView
@ -122,3 +123,48 @@ class EventProposalManageView(ProposalManageView):
model = EventProposal
template_name = "manage_eventproposal.html"
class MerchandiseOrdersView(BackofficeViewMixin, ListView):
template_name = "orders_merchandise.html"
def get_queryset(self, **kwargs):
camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y'))
return OrderProductRelation.objects.filter(
handed_out=False,
order__paid=True,
order__refunded=False,
order__cancelled=False,
product__category__name='Merchandise',
).filter(
product__name__startswith=camp_prefix
).order_by('order')
class MerchandiseToOrderView(BackofficeViewMixin, TemplateView):
template_name = "merchandise_to_order.html"
def get_context_data(self, **kwargs):
camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y'))
order_relations = OrderProductRelation.objects.filter(
handed_out=False,
order__paid=True,
order__refunded=False,
order__cancelled=False,
product__category__name='Merchandise',
).filter(
product__name__startswith=camp_prefix
)
merchandise_orders = {}
for relation in order_relations:
try:
quantity = merchandise_orders[relation.product.name] + relation.quantity
merchandise_orders[relation.product.name] = quantity
except KeyError:
merchandise_orders[relation.product.name] = relation.quantity
context = super().get_context_data(**kwargs)
context['merchandise'] = merchandise_orders
return context