update calculating prize for accounting

This commit is contained in:
2017-03-02 20:51:43 +01:00
parent d4a68683fa
commit 4df4a095cb
3 changed files with 25 additions and 28 deletions

View File

@@ -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: