2017-02-06 18:50:10 +01:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
from celery import shared_task
|
|
|
|
from . import models
|
2017-02-06 19:58:32 +01:00
|
|
|
from datetime import datetime
|
|
|
|
from . import utils
|
2017-02-06 18:50:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2017-02-06 19:11:32 +01:00
|
|
|
def process_location_data():
|
|
|
|
data = models.LocationData.objects.filter(processed=False)
|
|
|
|
for ld in data:
|
2017-02-06 19:58:32 +01:00
|
|
|
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()
|