show daily sale on location detail page

This commit is contained in:
Robert Einsle 2018-03-19 14:46:58 +01:00
parent f25ee6d198
commit a5c5c37a63
2 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,4 @@
{% load display_client %} {% load display_client display_daily_sale %}
{% if location.clients.all %} {% if location.clients.all %}
{% for cli in location.clients.all %} {% for cli in location.clients.all %}
{% for i in "12345678" %} {% for i in "12345678" %}
@ -10,3 +10,8 @@
<div class="alert alert-danger">Keine Tische angelegt!</div> <div class="alert alert-danger">Keine Tische angelegt!</div>
</div> </div>
{% endif %} {% endif %}
<div class="col">
<div class="alert alert-warning">
{{ location|display_daily_sale }}
</div>
</div>

View File

@ -0,0 +1,18 @@
from django import template
from billard.models import Accounting
from datetime import datetime, timedelta
from django.db.models import Sum
register = template.Library()
@register.filter(is_safe=True)
def display_daily_sale(location):
start_date = datetime.now().replace(hour=5, minute=0, second=0, microsecond=0)
end_date = start_date + timedelta(days=1)
prize__sum = Accounting.objects.filter(billed=True,
desk__client__location=location,
account_tst__range=(start_date, end_date)).aggregate(Sum('prize'))
if prize__sum['prize__sum'] is None:
prize__sum['prize__sum'] = 0
return "Tagesumsatz: {0:.2f} EUR".format(prize__sum['prize__sum'])