From dae777892bd60f81d9229c92a93466c0a8f08bdc Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Mon, 6 Feb 2017 19:58:32 +0100 Subject: [PATCH] add locationdata process logic --- billard/migrations/0005_auto_20170206_1926.py | 20 +++++++++++++++ billard/models.py | 13 +++++----- billard/tasks.py | 25 ++++++++++++++++--- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 billard/migrations/0005_auto_20170206_1926.py diff --git a/billard/migrations/0005_auto_20170206_1926.py b/billard/migrations/0005_auto_20170206_1926.py new file mode 100644 index 0000000..232d6a0 --- /dev/null +++ b/billard/migrations/0005_auto_20170206_1926.py @@ -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(), + ), + ] diff --git a/billard/models.py b/billard/models.py index 8bfe549..e8db414 100644 --- a/billard/models.py +++ b/billard/models.py @@ -4,18 +4,17 @@ from django.contrib.auth.models import User from datetime import datetime from . import utils from . import tasks -from caromserver import celery 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, name="Standort-ID") - table_no = models.IntegerField(blank=False, null=False, name="Tischnummer") - tst = models.DateTimeField(blank=False, null=False, name="Zeitstempel") - on_off = models.BooleanField(blank=False, null=False, name="Ein/Ausgebucht") - processed = models.BooleanField(default=False, name="Verarbeitet") - error_msg = models.CharField(max_length=16000, blank=True, null=True, name="Fehlermeldung") + location_id = models.UUIDField(blank=False, null=False) + table_no = models.IntegerField(blank=False, null=False) + tst = models.DateTimeField(blank=False, null=False) + on_off = models.BooleanField(blank=False, null=False) + processed = models.BooleanField(default=False) + error_msg = models.CharField(max_length=16000, blank=True, null=True) def __str__(self): return str(self.location_id) diff --git a/billard/tasks.py b/billard/tasks.py index 60e93cf..0e81fef 100644 --- a/billard/tasks.py +++ b/billard/tasks.py @@ -1,12 +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) - print(len(data)) for ld in data: - print(ld) - + 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()