From 3c500baf9900f44432f0de2c27872a48765cdcd7 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Mon, 6 Feb 2017 21:34:42 +0100 Subject: [PATCH] fix accounting --- billard/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/billard/models.py b/billard/models.py index c431663..4ebf838 100644 --- a/billard/models.py +++ b/billard/models.py @@ -56,11 +56,12 @@ class Client(models.Model): def accounting_for(self, desk_no, pht, pnt): t = Accounting.objects.filter(client_id=self.id, desk_no=desk_no)[:3][::-1] - a = t[t.__len__() - 1] - if a.time_to is None: - prize = utils.get_prize_for(start=a.time_from, end=datetime.now(timezone.utc), pph=pht) - if prize != a.prize: - a.prize = prize + if t.__len__() > 0: + a = t[t.__len__() - 1] + if a.time_to is None: + prize = utils.get_prize_for(start=a.time_from, end=datetime.now(timezone.utc), pph=pht) + if prize != a.prize: + a.prize = prize return t def accounting_1(self):