Calculate prize of rental
This commit is contained in:
parent
858cb5ce8d
commit
e63f8b7562
@ -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)
|
||||
|
@ -29,7 +29,7 @@
|
||||
<tr>
|
||||
<td>{{ acc.time_from|date:"d.m.Y H:i:s" }}</td>
|
||||
<td>{% if acc.time_to is not None %}{{ acc.time_to|date:"d.m.Y H:i:s" }}{% endif %}</td>
|
||||
<td>{% if acc.prize is not None %}{{ acc.prize }}{% endif %}</td>
|
||||
<td>{% if acc.prize is not None %}{{ acc.prize|floatformat:2 }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
@ -47,7 +47,7 @@
|
||||
<tr>
|
||||
<td>{{ acc.time_from|date:"d.m.Y H:i:s" }}</td>
|
||||
<td>{% if acc.time_to is not None %}{{ acc.time_to|date:"d.m.Y H:i:s" }}{% endif %}</td>
|
||||
<td>{% if acc.prize is not None %}{{ acc.prize }}{% endif %}</td>
|
||||
<td>{% if acc.prize is not None %}{{ acc.prize|floatformat:2 }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
24
billard/utils.py
Normal file
24
billard/utils.py
Normal file
@ -0,0 +1,24 @@
|
||||
from datetime import datetime, date, time
|
||||
|
||||
|
||||
def get_prize_for(start, end=datetime.now(), pph=0):
|
||||
'''
|
||||
calculate prize of billard table rental
|
||||
|
||||
:param start: start datetime of rental
|
||||
:param end: end datetime of rental
|
||||
:param pph: prize per hour of rental
|
||||
:return: the calculated prize of rental
|
||||
'''
|
||||
pps = pph / 3600
|
||||
time = (end - start).seconds
|
||||
prize = round((pps * time), 1)
|
||||
print(prize)
|
||||
return prize
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = date(2017, 2, 5)
|
||||
t = time(16, 00)
|
||||
start = datetime.combine(d, t)
|
||||
get_prize_for(start=start, pph=8.5)
|
Loading…
Reference in New Issue
Block a user