diff --git a/billard/admin.py b/billard/admin.py index 3e50dfc..c013dba 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -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') diff --git a/billard/migrations/0004_accounting.py b/billard/migrations/0004_accounting.py new file mode 100644 index 0000000..6039b09 --- /dev/null +++ b/billard/migrations/0004_accounting.py @@ -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')), + ], + ), + ] diff --git a/billard/models.py b/billard/models.py index 29bb03c..d0cb5bf 100644 --- a/billard/models.py +++ b/billard/models.py @@ -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'] diff --git a/billard/templates/billard/index.html b/billard/templates/billard/index.html index 5f9c46a..8128f7e 100644 --- a/billard/templates/billard/index.html +++ b/billard/templates/billard/index.html @@ -15,37 +15,35 @@ {% if clients %} {% for cli in clients %} {% if cli.desk1_enable %} -
+

(1) {{ cli.desk1_name }}

+{% if cli.accounting_1 %} +{% for acc in cli.accounting_1 %} - - - - - - - - + + + +{% endfor %}
01.02.2017 10:0001.02.2017 11:586,10
01.02.2017 10:0001.02.2017 11:586,10{{ acc.time_from }}{% if acc.time_to is not None %}{{ acc.time_to }}{% endif %}{% if acc.prize is not None %}{{ acc.prize }}{% endif %}
+{% endif %}
{% endif %} {% if cli.desk2_enable %} -
+

(2) {{ cli.desk2_name }}

+{% if cli.accounting_2 %} +{% for acc in cli.accounting_2 %} - - - - - - - - + + + +{% endfor %}
01.02.2017 10:0001.02.2017 11:586,10
01.02.2017 10:006,10{{ acc.time_from }}{% if acc.time_to is not None %}{{ acc.time_to }}{% endif %}{% if acc.prize is not None %}{{ acc.prize }}{% endif %}
+{% endif %}
{% endif %} {% endfor %}