show accounting data from table

This commit is contained in:
Robert Einsle 2017-02-01 20:25:33 +01:00
parent 90974ea783
commit 16243def6d
4 changed files with 76 additions and 18 deletions

View File

@ -18,3 +18,8 @@ class ClientAdmin(admin.ModelAdmin):
class LocationDataAdmin(admin.ModelAdmin):
list_display = ('location_id', 'table_no', 'tst', 'on_off', 'processed', 'error_msg')
fields = ['location_id', 'table_no', 'tst', 'on_off', 'processed', 'error_msg']
@admin.register(Accounting)
class AccountingAdmin(admin.ModelAdmin):
list_display = ('desk_no', 'time_from', 'time_to', 'prize')

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-01 19:08
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('billard', '0003_client'),
]
operations = [
migrations.CreateModel(
name='Accounting',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('desk_no', models.IntegerField()),
('time_from', models.DateTimeField()),
('time_to', models.DateTimeField(blank=True, null=True)),
('prize', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billard.Client')),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billard.Location')),
],
),
]

View File

@ -46,8 +46,35 @@ class Client(models.Model):
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):
return Accounting.objects.filter(location=self.location, desk_no=desk_no)[:2][::-1]
def accounting_1(self):
return self.accounting_for(1)
def accounting_2(self):
return self.accounting_for(2)
def __str__(self):
return str(self.uuid)
def __unicode__(self):
return str(self.location.name)
class Accounting(models.Model):
location = models.ForeignKey(Location)
client = models.ForeignKey(Client)
desk_no = models.IntegerField()
time_from = models.DateTimeField()
time_to = models.DateTimeField(blank=True, null=True)
prize = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
def __str__(self):
return self.location.name
def __unicode__(self):
return self.location.name
class Meta:
ordering = ['-time_from']

View File

@ -15,37 +15,35 @@
{% if clients %}
{% for cli in clients %}
{% if cli.desk1_enable %}
<div class="alert alert-success">
<div class="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>01.02.2017 10:00</td>
<td>01.02.2017 11:58</td>
<td>6,10</td>
</tr>
<tr>
<td>01.02.2017 10:00</td>
<td>01.02.2017 11:58</td>
<td>6,10</td>
<td>{{ acc.time_from }}</td>
<td>{% if acc.time_to is not None %}{{ acc.time_to }}{% endif %}</td>
<td>{% if acc.prize is not None %}{{ acc.prize }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endif %}
{% if cli.desk2_enable %}
<div class="alert alert-info">
<div class="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>01.02.2017 10:00</td>
<td>01.02.2017 11:58</td>
<td>6,10</td>
</tr>
<tr>
<td>01.02.2017 10:00</td>
<td></td>
<td>6,10</td>
<td>{{ acc.time_from }}</td>
<td>{% if acc.time_to is not None %}{{ acc.time_to }}{% endif %}</td>
<td>{% if acc.prize is not None %}{{ acc.prize }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endif %}
{% endfor %}