Add barman stats

This commit is contained in:
Skia 2016-11-25 16:04:55 +01:00
parent dcd0c1fe75
commit c48449cd50
3 changed files with 77 additions and 2 deletions

View File

@ -222,6 +222,7 @@ tbody>tr:hover {
}
.highlight {
background: orange;
font-weight: bold;
}
.tool-bar {
overflow: auto;

View File

@ -43,6 +43,56 @@
{% endfor %}
</tbody>
</table>
<h4>{% trans counter_name=counter.name %}Top 100 barman {{ counter_name }}{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Nb{% endtrans %}</td>
<td>{% trans %}User{% endtrans %}</td>
<td>{% trans %}Time{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for r in top_barman_semester %}
{% set u=User.objects.filter(id=r.user).first() %}
{% if u == user %}
<tr class="highlight">
{% else %}
<tr>
{% endif %}
<td>{{ loop.index }}</td>
<td>{{ u.get_display_name() }}</td>
<td>{{ r.perm_sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h4>{% trans counter_name=counter.name %}Top 100 barman {{ counter_name }} (all semesters){% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Nb{% endtrans %}</td>
<td>{% trans %}User{% endtrans %}</td>
<td>{% trans %}Time{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for r in top_barman %}
{% set u=User.objects.filter(id=r.user).first() %}
{% if u == user %}
<tr class="highlight">
{% else %}
<tr>
{% endif %}
<td>{{ loop.index }}</td>
<td>{{ u.get_display_name() }}</td>
<td>{{ r.perm_sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -11,7 +11,7 @@ from django.utils import timezone
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.db import DataError, transaction
from django.db import DataError, transaction, models
import re
import pytz
@ -23,7 +23,8 @@ from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMi
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
from core.models import User
from subscription.models import Subscription
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem, Eticket
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, \
CashRegisterSummary, CashRegisterSummaryItem, Eticket, Permanency
from accounting.models import CurrencyField
class GetUserForm(forms.Form):
@ -866,6 +867,7 @@ class CounterStatView(DetailView, CanEditMixin):
from django.db.models import Sum, Case, When, F, DecimalField
kwargs = super(CounterStatView, self).get_context_data(**kwargs)
kwargs['Customer'] = Customer
kwargs['User'] = User
semester_start = Subscription.compute_start(d=date.today(), duration=3)
kwargs['total_sellings'] = Selling.objects.filter(date__gte=semester_start,
counter=self.object).aggregate(total_sellings=Sum(F('quantity')*F('unit_price'),
@ -880,6 +882,28 @@ class CounterStatView(DetailView, CanEditMixin):
)
)
).exclude(selling_sum=None).order_by('-selling_sum').all()[:100]
kwargs['top_barman'] = Permanency.objects.values('user').annotate(
perm_sum=Sum(
Case(When(counter=self.object,
end__gt=datetime(year=1999, month=1, day=1),
then=F('end')-F('start')),
output_field=models.DateTimeField()
)
)
).exclude(perm_sum=None).order_by('-perm_sum').all()[:100]
kwargs['top_barman_semester'] = Permanency.objects.values('user').annotate(
perm_sum=Sum(
Case(When(counter=self.object,
start__gt=semester_start,
end__gt=datetime(year=1999, month=1, day=1),
then=F('end')-F('start')),
output_field=models.DateTimeField()
)
)
).exclude(perm_sum=None).order_by('-perm_sum').all()[:100]
kwargs['sith_date']=settings.SITH_START_DATE[0]
kwargs['semester_start']=semester_start
return kwargs
def dispatch(self, request, *args, **kwargs):