rebuild database structure, do single desk models

This commit is contained in:
Robert Einsle 2017-02-10 18:37:36 +01:00
parent 25808f4c5a
commit 7b76fdc62c
3 changed files with 67 additions and 1 deletions

View File

@ -10,7 +10,7 @@ class LocationAdmin(admin.ModelAdmin):
@admin.register(Client) @admin.register(Client)
class ClientAdmin(admin.ModelAdmin): class ClientAdmin(admin.ModelAdmin):
list_display = ('uuid', 'desk1_name', 'desk2_name') 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', ] fields = ['location', 'uuid', 'desk1_enable', 'desk1_name', 'desk1_prize_nt', 'desk1_prize_ht', 'desk2_enable', 'desk2_name', 'desk2_prize_nt', 'desk2_prize_ht', ]
@ -20,6 +20,11 @@ class LocationDataAdmin(admin.ModelAdmin):
fields = ['location_id', 'table_no', 'tst', 'on_off', 'processed', 'error_msg'] fields = ['location_id', 'table_no', 'tst', 'on_off', 'processed', 'error_msg']
@admin.register(Desk)
class DeskAdmin(admin.ModelAdmin):
list_display = ('client', 'desk_no', 'name', 'enabled', 'prize', 'prize_hh')
@admin.register(Accounting) @admin.register(Accounting)
class AccountingAdmin(admin.ModelAdmin): class AccountingAdmin(admin.ModelAdmin):
list_display = ('client', 'desk_no', 'time_from', 'time_to', 'prize') list_display = ('client', 'desk_no', 'time_from', 'time_to', 'prize')

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-10 18:30
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('billard', '0006_auto_20170206_2031'),
]
operations = [
migrations.CreateModel(
name='Desk',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('desk_no', models.IntegerField(verbose_name='Tischnummer')),
('name', models.CharField(blank=True, max_length=32, null=True, verbose_name='Tischbezeichnung')),
('enabled', models.BooleanField(verbose_name='Tisch aktiv')),
('prize', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True, verbose_name='Normelpreis')),
('prize_hh', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True, verbose_name='Preis Happy Hour')),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='billard.Client', verbose_name='Client')),
],
options={
'verbose_name_plural': 'Tische',
'verbose_name': 'Tisch',
},
),
]

View File

@ -23,6 +23,7 @@ class LocationData(models.Model):
verbose_name = "Standortlog" verbose_name = "Standortlog"
verbose_name_plural = "Standortlogs" verbose_name_plural = "Standortlogs"
class Location(models.Model): class Location(models.Model):
users = models.ManyToManyField(User, related_name='locations', verbose_name="Benutzer") users = models.ManyToManyField(User, related_name='locations', verbose_name="Benutzer")
code = models.CharField(max_length=16, unique=True, verbose_name="Code") code = models.CharField(max_length=16, unique=True, verbose_name="Code")
@ -77,6 +78,34 @@ class Client(models.Model):
verbose_name = "Client" verbose_name = "Client"
verbose_name_plural = "Clienten" verbose_name_plural = "Clienten"
class Desk(models.Model):
client = models.ForeignKey(Client, verbose_name='Client')
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')
prize = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Normelpreis")
prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True,
verbose_name="Preis Happy Hour")
def accounting_for(self):
t = Accounting.objects.filter(client=self.client, desk_no=self.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=self.prize)
if prize != a.prize:
a.prize = prize
return t
def __str__(self):
return '{}, {}'.format(self.client.uuid, self.name)
class Meta:
verbose_name = "Tisch"
verbose_name_plural = "Tische"
class Accounting(models.Model): class Accounting(models.Model):
client = models.ForeignKey(Client, verbose_name="Client") client = models.ForeignKey(Client, verbose_name="Client")
desk_no = models.IntegerField(verbose_name="Tischnummer") desk_no = models.IntegerField(verbose_name="Tischnummer")