diff --git a/billard/models.py b/billard/models.py index 54ce203..1289a72 100644 --- a/billard/models.py +++ b/billard/models.py @@ -127,16 +127,17 @@ def process_location_data(): desk = desk[0] ac = desk.accounting_set.order_by('time_from').reverse() if ld.on_off: + acc = None if ac.count() > 0 and ac[0].time_to is None: - ac[0].time_to = ld.tst - ac[0].save() mail_admins(subject='Accounting passt nicht', message='Vorheriges Accounting nicht abgeschlossen: Desk_id {}, Accounting_id {}' .format(desk.id, ac[0].id)) - acc = Accounting( - desk=desk, - time_from=ld.tst, - ) + acc = ac[0] + if acc is None: + acc = Accounting( + desk=desk, + time_from=ld.tst, + ) acc.save() ld.delete() else: