update template using new desk model

This commit is contained in:
Robert Einsle 2017-02-10 19:39:21 +01:00
parent 7b76fdc62c
commit 55cdfc0509
7 changed files with 107 additions and 64 deletions

View File

@ -10,8 +10,8 @@ class LocationAdmin(admin.ModelAdmin):
@admin.register(Client)
class ClientAdmin(admin.ModelAdmin):
list_display = ('uuid', 'location', 'desk1_name', 'desk2_name')
fields = ['location', 'uuid', 'desk1_enable', 'desk1_name', 'desk1_prize_nt', 'desk1_prize_ht', 'desk2_enable', 'desk2_name', 'desk2_prize_nt', 'desk2_prize_ht', ]
list_display = ('uuid', 'location')
fields = ['location', 'uuid']
@admin.register(LocationData)

View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-10 19:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('billard', '0007_desk'),
]
operations = [
migrations.RemoveField(
model_name='client',
name='desk1_enable',
),
migrations.RemoveField(
model_name='client',
name='desk1_name',
),
migrations.RemoveField(
model_name='client',
name='desk1_prize_ht',
),
migrations.RemoveField(
model_name='client',
name='desk1_prize_nt',
),
migrations.RemoveField(
model_name='client',
name='desk2_enable',
),
migrations.RemoveField(
model_name='client',
name='desk2_name',
),
migrations.RemoveField(
model_name='client',
name='desk2_prize_ht',
),
migrations.RemoveField(
model_name='client',
name='desk2_prize_nt',
),
migrations.AlterField(
model_name='desk',
name='client',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='desks', to='billard.Client', verbose_name='Client'),
),
]

View File

@ -46,30 +46,6 @@ class Location(models.Model):
class Client(models.Model):
uuid = models.UUIDField(unique=True, default=uuid.uuid4, verbose_name="Identifier")
location = models.ForeignKey(Location, verbose_name="Standort")
desk1_enable = models.BooleanField()
desk1_name = models.CharField(max_length=32, blank=True, null=True)
desk1_prize_nt = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True)
desk1_prize_ht = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True)
desk2_enable = models.BooleanField()
desk2_name = models.CharField(max_length=32, blank=True, null=True)
desk2_prize_nt = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True)
desk2_prize_ht = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True)
def accounting_for(self, desk_no, pht, pnt):
t = Accounting.objects.filter(client_id=self.id, desk_no=desk_no)[:3][::-1]
if t.__len__() > 0:
a = t[t.__len__() - 1]
if a.time_to is None:
prize = utils.get_prize_for(start=a.time_from, end=datetime.now(timezone.utc), pph=pht)
if prize != a.prize:
a.prize = prize
return t
def accounting_1(self):
return self.accounting_for(1, self.desk1_prize_ht, self.desk1_prize_nt)
def accounting_2(self):
return self.accounting_for(2, self.desk2_prize_ht, self.desk2_prize_nt)
def __str__(self):
return '{}, {}'.format(self.location.name, self.uuid)
@ -80,7 +56,7 @@ class Client(models.Model):
class Desk(models.Model):
client = models.ForeignKey(Client, verbose_name='Client')
client = models.ForeignKey(Client, verbose_name='Client', related_name='desks')
desk_no = models.IntegerField(verbose_name='Tischnummer')
name = models.CharField(max_length=32, blank=True, null=True, verbose_name='Tischbezeichnung')
enabled = models.BooleanField(verbose_name='Tisch aktiv')

View File

@ -1,4 +1,5 @@
{% extends 'billard/base.html' %}
{% load display_client %}
{% block header %}
<meta http-equiv="refresh" content="3" />
@ -19,42 +20,7 @@
</form>
{% if clients %}
{% for cli in clients %}
{% if cli.desk1_enable %}
<div class="col-md-6">
<div class="col-md-12 table-info alert {% with cli.accounting_1|last as last %}{% if last.time_to is None %}alert-info{% else %}alert-success{% endif %}{% endwith %}">
<h4 style="text-align: center">(1) {{ cli.desk1_name }}</h4>
{% if cli.accounting_1 %}
<table class="table">
{% for acc in cli.accounting_1 %}
<tr>
<td>{{ acc.time_from|date:"d.m.Y H:i:s" }}</td>
<td>{% if acc.time_to is not None %}{{ acc.time_to|date:"d.m.Y H:i:s" }}{% endif %}</td>
<td style="text-align: center;">{% if acc.prize is not None %}{{ acc.prize|floatformat:2 }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>
{% endif %}
{% if cli.desk2_enable %}
<div class="col-md-6">
<div class="col-md-12 table-info alert {% with cli.accounting_2|last as last %}{% if last.time_to is None %}alert-info{% else %}alert-success{% endif %}{% endwith %}">
<h4 style="text-align: center">(2) {{ cli.desk2_name }}</h4>
{% if cli.accounting_2 %}
<table class="table">
{% for acc in cli.accounting_2 %}
<tr>
<td>{{ acc.time_from|date:"d.m.Y H:i:s" }}</td>
<td>{% if acc.time_to is not None %}{{ acc.time_to|date:"d.m.Y H:i:s" }}{% endif %}</td>
<td style="text-align: right;">{% if acc.prize is not None %}{{ acc.prize|floatformat:2 }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>
{% endif %}
{% for i in range %} {{ cli|display_client:i }} {% endfor %}
{% endfor %}
{% else %}
<div class="col-md-12">

View File

View File

@ -0,0 +1,48 @@
from django import template
from django.utils.html import format_html
from billard.models import Desk, Accounting
from billard import utils
from datetime import datetime, timezone
register = template.Library()
@register.filter(is_safe=True)
def display_client(client, desk_no):
desks = client.desks.filter(desk_no=desk_no)
if len(desks) == 0:
return ''
desk = desks[0]
if not desk.enabled:
return ''
alert = 'alert-success'
acc = Accounting.objects.filter(client=client, desk_no=desk_no)[:3][::-1]
if acc is not None and len(acc) > 0:
a = acc[-1]
if a.time_to is None:
alert = 'alert-info'
prize = utils.get_prize_for(start=a.time_from, end=datetime.now(), pph=desk.prize)
prize = '{0:.2f}'.format(prize)
if prize != a.prize:
a.prize = prize
html = '<div class="col-md-6">\n'
html += ' <div class="col-md-12 table-info alert {}">\n'.format(alert)
html += ' <h4 style="text-align: center">({}) {}</h4>\n'.format(desk_no, desk.name)
if len(acc) > 0:
html += ' <table class="table">\n'
for a in acc:
html += ' <tr>\n'
html += ' <td>{}</td>\n'.format(a.time_from)
html += ' <td>{}</td>\n'.format((a.time_to if a.time_to is not None else ''))
html += ' <td style="text-align: center;">{}</td>\n'\
.format((a.prize if a.prize is not None else ''))
html += ' <tr>\n'
html += ' <tr>\n'
html += ' </tr>\n'
html += ' </table>\n'
html += ' </div>\n'
html += '</div>\n'
html = format_html(html)
return html

View File

@ -55,7 +55,7 @@ def index(request):
locations = Location.objects.filter(users__id=request.user.id).order_by('code')
clients = Client.objects.filter(location_id=loc).order_by('id')
context = {
'range': range(1, 3),
'range': range(1, 9),
'locations': locations,
'clients': clients,
'location_id': int(loc),