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()