add locationdata process logic
This commit is contained in:
parent
3a48ac9c6b
commit
dae777892b
20
billard/migrations/0005_auto_20170206_1926.py
Normal file
20
billard/migrations/0005_auto_20170206_1926.py
Normal 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(),
|
||||||
|
),
|
||||||
|
]
|
@ -4,18 +4,17 @@ from django.contrib.auth.models import User
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from . import utils
|
from . import utils
|
||||||
from . import tasks
|
from . import tasks
|
||||||
from caromserver import celery
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
|
|
||||||
|
|
||||||
class LocationData(models.Model):
|
class LocationData(models.Model):
|
||||||
location_id = models.CharField(max_length=32, blank=False, null=False, name="Standort-ID")
|
location_id = models.UUIDField(blank=False, null=False)
|
||||||
table_no = models.IntegerField(blank=False, null=False, name="Tischnummer")
|
table_no = models.IntegerField(blank=False, null=False)
|
||||||
tst = models.DateTimeField(blank=False, null=False, name="Zeitstempel")
|
tst = models.DateTimeField(blank=False, null=False)
|
||||||
on_off = models.BooleanField(blank=False, null=False, name="Ein/Ausgebucht")
|
on_off = models.BooleanField(blank=False, null=False)
|
||||||
processed = models.BooleanField(default=False, name="Verarbeitet")
|
processed = models.BooleanField(default=False)
|
||||||
error_msg = models.CharField(max_length=16000, blank=True, null=True, name="Fehlermeldung")
|
error_msg = models.CharField(max_length=16000, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.location_id)
|
return str(self.location_id)
|
||||||
|
@ -1,12 +1,31 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from . import models
|
from . import models
|
||||||
|
from datetime import datetime
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def process_location_data():
|
def process_location_data():
|
||||||
data = models.LocationData.objects.filter(processed=False)
|
data = models.LocationData.objects.filter(processed=False)
|
||||||
print(len(data))
|
|
||||||
for ld in 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user