update calculating prize for accounting
This commit is contained in:
parent
d4a68683fa
commit
4df4a095cb
@ -71,24 +71,6 @@ class Desk(models.Model):
|
||||
prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True,
|
||||
verbose_name="Preis Happy Hour")
|
||||
|
||||
def accounting_for(self):
|
||||
t = Accounting.objects.filter(client=self.client, desk_no=self.desk_no)[:3][::-1]
|
||||
client = self.client
|
||||
location = client.location
|
||||
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=self.prize,
|
||||
hh_start=location.happy_hour_start,
|
||||
hh_end=location.happy_hour_end,
|
||||
pphh=self.prize_hh,
|
||||
)
|
||||
if prize != a.prize:
|
||||
a.prize = prize
|
||||
return t
|
||||
|
||||
def __str__(self):
|
||||
return '{}, {}'.format(self.client.uuid, self.name)
|
||||
@ -105,6 +87,8 @@ class Accounting(models.Model):
|
||||
prize = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis")
|
||||
billed = models.BooleanField(default=False, verbose_name="Abgerechnet")
|
||||
reporter_uuid = models.UUIDField(blank=True, null=True, verbose_name='Reporter UUID')
|
||||
prize_normal = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Normalzeit")
|
||||
prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour")
|
||||
|
||||
def __str__(self):
|
||||
return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed)
|
||||
@ -157,7 +141,7 @@ def process_location_data():
|
||||
if len(ac) > 0:
|
||||
acc = ac[0]
|
||||
acc.time_to = ld.tst
|
||||
acc.prize = utils.get_prize_for(
|
||||
acc.prize, acc.prize_normal, acc.prize_hh = utils.get_prize_for(
|
||||
start=acc.time_from,
|
||||
end=ld.tst,
|
||||
pph=desk.prize,
|
||||
|
@ -22,7 +22,7 @@ def display_client(client, desk_no):
|
||||
a = acc[-1]
|
||||
if a.time_to is None:
|
||||
alert = 'alert-info'
|
||||
prize = utils.get_prize_for(
|
||||
prize, u1, u2 = utils.get_prize_for(
|
||||
start=a.time_from,
|
||||
end=datetime.now(),
|
||||
pph=desk.prize,
|
||||
|
@ -16,6 +16,8 @@ def get_prize_for(start, end, pph=0, hh_start=None, hh_end=None, pphh=0):
|
||||
if end <= start:
|
||||
raise ValueError('end date must be after start date')
|
||||
prize = 0
|
||||
prize_normal = 0
|
||||
prize_hh = 0
|
||||
if hh_start is not None and hh_end is not None and pphh is not None:
|
||||
d = start.date()
|
||||
t = start.time()
|
||||
@ -24,35 +26,46 @@ def get_prize_for(start, end, pph=0, hh_start=None, hh_end=None, pphh=0):
|
||||
while True:
|
||||
if t < hh_start:
|
||||
if end_time < hh_start and d == end_date:
|
||||
prize += calculate_prize_for(start=t, end=end_time, pph=pph)
|
||||
p = calculate_prize_for(start=t, end=end_time, pph=pph)
|
||||
prize += p
|
||||
prize_normal += p
|
||||
break
|
||||
else:
|
||||
prize += calculate_prize_for(start=t, end=hh_start, pph=pph)
|
||||
p += calculate_prize_for(start=t, end=hh_start, pph=pph)
|
||||
prize += p
|
||||
prize_normal += p
|
||||
t = hh_start
|
||||
elif hh_start <= t < hh_end:
|
||||
if end_time < hh_end and d == end_date:
|
||||
prize += calculate_prize_for(start=t, end=end_time, pph=pphh)
|
||||
p += calculate_prize_for(start=t, end=end_time, pph=pphh)
|
||||
prize += p
|
||||
prize_hh += p
|
||||
break
|
||||
else:
|
||||
prize += calculate_prize_for(start=t, end=hh_end, pph=pphh)
|
||||
p += calculate_prize_for(start=t, end=hh_end, pph=pphh)
|
||||
prize += p
|
||||
prize_hh += p
|
||||
t = hh_end
|
||||
else:
|
||||
if d == end_date:
|
||||
prize += calculate_prize_for(start=t, end=end_time, pph=pph)
|
||||
p += calculate_prize_for(start=t, end=end_time, pph=pph)
|
||||
prize += p
|
||||
prize_normal += p
|
||||
break
|
||||
else:
|
||||
prize += calculate_prize_for(start=t, end=datetime.strptime('23:59:59', '%H:%M:%S').time(), pph=pph)
|
||||
p += calculate_prize_for(start=t, end=datetime.strptime('23:59:59', '%H:%M:%S').time(), pph=pph)
|
||||
prize += p
|
||||
prize_normal += p
|
||||
t = datetime.strptime('00:00:00', '%H:%M:%S').time()
|
||||
d = (datetime.combine(d, t) + timedelta(days=1)).date()
|
||||
else:
|
||||
prize = calculate_prize_for(start=start, end=end, pph=pph)
|
||||
return prize
|
||||
return prize, prize_normal, prize_hh
|
||||
|
||||
|
||||
def calculate_prize_for(start, end, pph=0):
|
||||
pps = pph / 3600
|
||||
d = date.today()
|
||||
seconds = 0
|
||||
if isinstance(start, datetime):
|
||||
seconds = (end - start).seconds
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user