diff --git a/billard/models.py b/billard/models.py index 01f0bfa..4adc6ad 100644 --- a/billard/models.py +++ b/billard/models.py @@ -1,6 +1,8 @@ import uuid from django.db import models from django.contrib.auth.models import User +from datetime import datetime +from . import utils class LocationData(models.Model): @@ -48,14 +50,20 @@ class Client(models.Model): desk2_prize_nt = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) desk2_prize_ht = models.DecimalField(max_digits=4, decimal_places=2, blank=True, null=True) - def accounting_for(self, desk_no): - return Accounting.objects.filter(client_id=self.id, desk_no=desk_no)[:2][::-1] + 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(), pph=pht) + if prize != a.prize: + a.prize = prize + return t def accounting_1(self): - return self.accounting_for(1) + return self.accounting_for(1, self.desk1_prize_ht, self.desk1_prize_nt) def accounting_2(self): - return self.accounting_for(2) + return self.accounting_for(2, self.desk2_prize_ht, self.desk2_prize_nt) def __str__(self): return '{}, {}'.format(self.location.name, self.uuid) diff --git a/billard/templates/billard/index.html b/billard/templates/billard/index.html index c2c613d..a4e4c02 100644 --- a/billard/templates/billard/index.html +++ b/billard/templates/billard/index.html @@ -29,7 +29,7 @@