Merge branch 'develop' of git.einsle.de:carom/carom-server into develop

Conflicts:
	billard/models.py
This commit is contained in:
Alexander Werner
2017-02-06 20:28:26 +01:00
6 changed files with 107 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-06 18:26
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('billard', '0004_accounting'),
]
operations = [
migrations.AlterField(
model_name='locationdata',
name='location_id',
field=models.UUIDField(),
),
]

View File

@@ -1,12 +1,15 @@
import uuid
from django.db import models
from django.contrib.auth.models import User
from datetime import datetime
from datetime import datetime, timezone
from . import utils
from . import tasks
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class LocationData(models.Model):
location_id = models.CharField(max_length=32, blank=False, null=False, verbose_name="Standort-ID")
location_id = models.UUIDField(blank=False, null=False, verbose_name="Standort-ID")
table_no = models.IntegerField(blank=False, null=False, verbose_name="Tischnummer")
tst = models.DateTimeField(blank=False, null=False, verbose_name="Zeitstempel")
on_off = models.BooleanField(blank=False, null=False, verbose_name="Ein/Ausgebucht")
@@ -55,7 +58,7 @@ class Client(models.Model):
t = Accounting.objects.filter(client_id=self.id, desk_no=desk_no)[:3][::-1]
a = t[t.__len__() - 1]
if a.time_to is None:
prize = utils.get_prize_for(start=a.time_from, end=datetime.now(), pph=pht)
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
@@ -86,4 +89,10 @@ class Accounting(models.Model):
class Meta:
ordering = ['-time_from']
verbose_name = "Buchhaltungseintrag"
verbose_name_plural = "Buchhaltungseinträge"
verbose_name_plural = "Buchhaltungseinträge"
def update_location_data(sender, instance, **kwargs):
tasks.process_location_data.delay()
post_save.connect(update_location_data, sender=LocationData)

31
billard/tasks.py Normal file
View File

@@ -0,0 +1,31 @@
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from . import models
from datetime import datetime
from . import utils
@shared_task
def process_location_data():
data = models.LocationData.objects.filter(processed=False)
for ld in data:
cli = models.Client.objects.get(uuid=ld.location_id)
ac = models.Accounting.objects.filter(client=cli).order_by('time_from').reverse()[0]
if ld.on_off:
if ac.time_to is None:
ac.time_to = datetime.now()
ac.save()
ac = models.Accounting(
client=cli,
desk_no=ld.table_no,
time_from=ld.tst,
)
ac.save()
ld.processed=True
ld.save()
else:
ac.time_to = ld.tst
ac.prize = utils.get_prize_for(start=ac.time_from, end=ac.time_to, pph=cli.desk1_prize_ht)
ac.save()
ld.processed=True
ld.save()