From 0a36d3904e4bfb772762ee5c8210d7ec8bf2ef31 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Mon, 27 Feb 2017 07:58:06 +0100 Subject: [PATCH 01/20] extend accounting model --- .../0017_accounting_reporter_uuid.py | 20 +++++++++++++++++++ billard/models.py | 1 + 2 files changed, 21 insertions(+) create mode 100644 billard/migrations/0017_accounting_reporter_uuid.py 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/models.py b/billard/models.py index f9c673b..71b3039 100644 --- a/billard/models.py +++ b/billard/models.py @@ -104,6 +104,7 @@ class Accounting(models.Model): time_to = models.DateTimeField(blank=True, null=True, verbose_name="Ende") 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') def __str__(self): return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed) From d4a68683fa5adcf5c6bda3432b5b22314077f2c3 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Mon, 27 Feb 2017 08:01:58 +0100 Subject: [PATCH 02/20] update accounting using location data uuid --- billard/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/billard/models.py b/billard/models.py index 71b3039..b0f5d91 100644 --- a/billard/models.py +++ b/billard/models.py @@ -165,6 +165,7 @@ def process_location_data(): hh_end=cli.location.happy_hour_end, pphh=desk.prize_hh, ) + acc.reporter_uuid = ld.client_id acc.save() ld.delete() else: From 3a2c21cbc23994a7877278301ce756352defd7f4 Mon Sep 17 00:00:00 2001 From: Alexander Werner Date: Thu, 2 Mar 2017 20:25:40 +0100 Subject: [PATCH 03/20] Added modal view --- billard/models.py | 3 ++- billard/templates/billard/index_ajax.html | 20 ++++++++++++++++++++ billard/views.py | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/billard/models.py b/billard/models.py index b0f5d91..67511a6 100644 --- a/billard/models.py +++ b/billard/models.py @@ -53,6 +53,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, verbose_name="Reporting Benutzer", related_name='reporting_clients') def __str__(self): return '{}, {}'.format(self.location.name, self.uuid) @@ -172,4 +173,4 @@ def process_location_data(): ld.processed = True ld.error_msg = 'No existing accountings found. Stopp processing! {}, {}'.format(ld.client_id, ld.desk_no) ld.save() - log.error(ld.error_msg) + log.error(ld.error_msg) \ No newline at end of file diff --git a/billard/templates/billard/index_ajax.html b/billard/templates/billard/index_ajax.html index 10d7261..bd0d345 100644 --- a/billard/templates/billard/index_ajax.html +++ b/billard/templates/billard/index_ajax.html @@ -7,4 +7,24 @@
Keine Tische angelegt!
+{% endif %} +{% if accounts %} + {% endif %} \ No newline at end of file diff --git a/billard/views.py b/billard/views.py index 553ab9c..7775eb0 100644 --- a/billard/views.py +++ b/billard/views.py @@ -54,11 +54,13 @@ def index(request): loc = min_loc locations = Location.objects.filter(users__id=request.user.id).order_by('code') clients = Client.objects.filter(location_id=loc).order_by('id') + accounts = Accounting.objects.filter(reporter_uuid__in=Client.objects.filter(report_user=request.user)) context = { 'range': range(1, 9), 'locations': locations, 'clients': clients, 'location_id': int(loc), + 'accounts': accounts, } return render(request, template, context=context) if request.method == 'POST': From 4df4a095cb9a49ef6e5f8628392f28e8ddb47064 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 2 Mar 2017 20:51:43 +0100 Subject: [PATCH 04/20] update calculating prize for accounting --- billard/models.py | 22 +++---------------- billard/templatetags/display_client.py | 2 +- billard/utils.py | 29 +++++++++++++++++++------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/billard/models.py b/billard/models.py index b0f5d91..0a5f197 100644 --- a/billard/models.py +++ b/billard/models.py @@ -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, 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/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: From 943ff5ad216b575c41284cb9092dc703cbc84f8a Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 2 Mar 2017 20:59:10 +0100 Subject: [PATCH 05/20] update model --- billard/migrations/0018_auto_20170302_2058.py | 33 +++++++++++++++++++ billard/models.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 billard/migrations/0018_auto_20170302_2058.py 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 952070e..205aaca 100644 --- a/billard/models.py +++ b/billard/models.py @@ -53,7 +53,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, verbose_name="Reporting Benutzer", related_name='reporting_clients') + 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) From f89306dfde3be2031aa124ab9d08d7578b0f7881 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 2 Mar 2017 21:01:07 +0100 Subject: [PATCH 06/20] updating admin --- billard/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 63e9c348a072862aa6b7eb9910f69578c2a59a71 Mon Sep 17 00:00:00 2001 From: Alexander Werner Date: Mon, 6 Mar 2017 18:43:17 +0100 Subject: [PATCH 07/20] updated modal code --- billard/templates/billard/index.html | 3 ++- billard/templates/billard/index_ajax.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/billard/templates/billard/index.html b/billard/templates/billard/index.html index 31bffd6..aaa79f2 100644 --- a/billard/templates/billard/index.html +++ b/billard/templates/billard/index.html @@ -28,7 +28,8 @@ $(document).ready(function() { }); function refresh_page() { - $('#desk_data').load('#') + $('#desk_data').load('#'); + $('#accountsmodal').modal(); } {% endblock %} diff --git a/billard/templates/billard/index_ajax.html b/billard/templates/billard/index_ajax.html index bd0d345..665bd2e 100644 --- a/billard/templates/billard/index_ajax.html +++ b/billard/templates/billard/index_ajax.html @@ -9,7 +9,7 @@ {% endif %} {% if accounts %} -