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 21:25:45 +01:00
|
|
|
cli = models.Client.objects.filter(uuid=ld.location_id)
|
|
|
|
if cli.count() < 1:
|
|
|
|
ld.processed = True
|
|
|
|
ld.error_msg = 'No location object found. Stopp processing!'
|
2017-02-06 19:58:32 +01:00
|
|
|
ld.save()
|
2017-02-06 21:25:45 +01:00
|
|
|
# TODO Send error eMail to Admin
|
2017-02-06 19:58:32 +01:00
|
|
|
else:
|
2017-02-06 21:25:45 +01:00
|
|
|
cli = cli[0]
|
2017-02-09 20:51:09 +01:00
|
|
|
ac = models.Accounting.objects.filter(client=cli, desk_no=ld.table_no).order_by('time_from').reverse()
|
2017-02-06 21:25:45 +01:00
|
|
|
if ld.on_off:
|
|
|
|
if ac.count() > 0 and ac[0].time_to is None:
|
|
|
|
ac[0].time_to = datetime.now()
|
|
|
|
ac[0].save()
|
|
|
|
# TODO Send error eMail to Admin
|
|
|
|
acc = models.Accounting(
|
|
|
|
client=cli,
|
|
|
|
desk_no=ld.table_no,
|
|
|
|
time_from=ld.tst,
|
|
|
|
)
|
|
|
|
acc.save()
|
|
|
|
ld.delete()
|
|
|
|
else:
|
|
|
|
acc = ac[0]
|
|
|
|
acc.time_to = ld.tst
|
|
|
|
acc.prize = utils.get_prize_for(
|
|
|
|
start=acc.time_from,
|
|
|
|
end=ld.tst,
|
|
|
|
pph=cli.desk1_prize_ht
|
|
|
|
)
|
|
|
|
acc.save()
|
|
|
|
ld.delete()
|