diff --git a/billard/admin.py b/billard/admin.py index 970cd8d..ba4744f 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -27,8 +27,8 @@ class LocationAdmin(admin.ModelAdmin): @admin.register(Client) class ClientAdmin(admin.ModelAdmin): - list_display = ('uuid', 'location') - fields = ['location', 'uuid'] + list_display = ('uuid', 'location', 'report_user') + fields = ['location', 'uuid', 'report_user'] @admin.register(LocationData) diff --git a/billard/migrations/0017_accounting_reporter_uuid.py b/billard/migrations/0017_accounting_reporter_uuid.py new file mode 100644 index 0000000..e4c09fa --- /dev/null +++ b/billard/migrations/0017_accounting_reporter_uuid.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-02-27 07:57 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('billard', '0016_auto_20170225_1822'), + ] + + operations = [ + migrations.AddField( + model_name='accounting', + name='reporter_uuid', + field=models.UUIDField(blank=True, null=True, verbose_name='Reporter UUID'), + ), + ] diff --git a/billard/migrations/0018_auto_20170302_2058.py b/billard/migrations/0018_auto_20170302_2058.py new file mode 100644 index 0000000..ba2c4a7 --- /dev/null +++ b/billard/migrations/0018_auto_20170302_2058.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-03-02 20:58 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('billard', '0017_accounting_reporter_uuid'), + ] + + operations = [ + migrations.AddField( + model_name='accounting', + name='prize_hh', + field=models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True, verbose_name='Preis Happy Hour'), + ), + migrations.AddField( + model_name='accounting', + name='prize_normal', + field=models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True, verbose_name='Preis Normalzeit'), + ), + migrations.AddField( + model_name='client', + name='report_user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='reporting_clients', to=settings.AUTH_USER_MODEL, verbose_name='Reporting Benutzer'), + ), + ] diff --git a/billard/models.py b/billard/models.py index 824e825..33aedfe 100644 --- a/billard/models.py +++ b/billard/models.py @@ -51,6 +51,7 @@ class Location(models.Model): class Client(models.Model): uuid = models.UUIDField(unique=True, default=uuid.uuid4, verbose_name="Identifier") location = models.ForeignKey(Location, verbose_name="Standort") + report_user = models.ForeignKey(User, blank=True, null=True, verbose_name="Reporting Benutzer", related_name='reporting_clients') def __str__(self): return '{}, {}'.format(self.location.name, self.uuid) @@ -69,24 +70,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) @@ -102,6 +85,9 @@ class Accounting(models.Model): time_to = models.DateTimeField(blank=True, null=True, verbose_name="Ende") prize = models.DecimalField(max_digits=6, 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) @@ -116,5 +102,3 @@ class Accounting(models.Model): def test(sender, **kwargs): from .tasks import process_location_data process_location_data.delay() - - diff --git a/billard/serializers.py b/billard/serializers.py index 8cccd42..fcf57e7 100644 --- a/billard/serializers.py +++ b/billard/serializers.py @@ -1,4 +1,4 @@ -from billard.models import * +from billard.models import LocationData from rest_framework import serializers diff --git a/billard/templates/billard/accountmodal.html b/billard/templates/billard/accountmodal.html new file mode 100644 index 0000000..9d0b008 --- /dev/null +++ b/billard/templates/billard/accountmodal.html @@ -0,0 +1,30 @@ +{% if account %} + +{% endif %} \ No newline at end of file diff --git a/billard/templates/billard/index.html b/billard/templates/billard/index.html index 31bffd6..398718e 100644 --- a/billard/templates/billard/index.html +++ b/billard/templates/billard/index.html @@ -19,16 +19,25 @@
{% include 'billard/index_ajax.html' %}
+ {% endblock %} {% block js %} {% endblock %} diff --git a/billard/templatetags/display_client.py b/billard/templatetags/display_client.py index 27fc38d..28a1a41 100644 --- a/billard/templatetags/display_client.py +++ b/billard/templatetags/display_client.py @@ -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, diff --git a/billard/urls.py b/billard/urls.py index 5f2c954..5f22fdc 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -9,5 +9,7 @@ urlpatterns = [ url(r'^$', views.index, name='carom_index'), url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), url(r'api/v1/', include(router.urls)), - url(r'process_locationdata', views.process_locationdata, name='process_locationdata') + url(r'process_locationdata', views.process_locationdata, name='process_locationdata'), + url(r'accountmodal$', views.accountmodalview, name='accountmodal'), + url(r'accoutmodal/confirm/(?P[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm") ] diff --git a/billard/utils.py b/billard/utils.py index d93156d..302bd82 100644 --- a/billard/utils.py +++ b/billard/utils.py @@ -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: diff --git a/billard/views.py b/billard/views.py index 3f68775..8cab675 100644 --- a/billard/views.py +++ b/billard/views.py @@ -23,6 +23,7 @@ class IndexView(generic.ListView): return ('billard/locationdata_list_ajax.html',) return super().get_template_names() + class LocationDataDetailView(DetailView): model = LocationData @@ -32,6 +33,26 @@ class LocationDataDetailView(DetailView): return super().get_template_names() +@login_required +def accountmodalview(request): + try: + account = Accounting.objects.filter(reporter_uuid=Client.objects.get(report_user=request.user).uuid).first + except Client.DoesNotExist: + account = None + context = { + 'account': account + } + return render(request, 'billard/accountmodal.html', context=context) + + +@login_required +def accountmodalconfirmview(request, pk): + account = Accounting.objects.get(pk=pk) + account.reporter_uuid = None + account.save() + return redirect('carom_index') + + @login_required def index(request): if request.method == 'GET': diff --git a/requirements.txt b/requirements.txt index d75daee..0b4d8d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ celery==4.0.2 Django==1.10.5 django-crispy-forms==1.6.1 -django-extensions==1.7.6 +django-extensions==1.7.7 djangorestframework==3.5.4 requests==2.13.0