From 399b6dc16deadecd65d2919681598e73b12b5fb4 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Wed, 2 Sep 2020 22:47:19 +0200 Subject: [PATCH] add some aggregation and stuff on posreports in backoffice --- .../includes/posreport_list_table.html | 20 ++++-- .../templates/posreport_detail.html | 10 ++- src/backoffice/views.py | 8 ++- .../0016_posreport_hax_sold_izettle.py | 21 ++++++ src/economy/models.py | 70 ++++++++++++++++++- 5 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 src/economy/migrations/0016_posreport_hax_sold_izettle.py diff --git a/src/backoffice/templates/includes/posreport_list_table.html b/src/backoffice/templates/includes/posreport_list_table.html index 3f722658..4fc363e1 100644 --- a/src/backoffice/templates/includes/posreport_list_table.html +++ b/src/backoffice/templates/includes/posreport_list_table.html @@ -4,8 +4,14 @@ Date Pos - Bank Responsible - Pos Responsible + Responsible + Bank Start + Pos Start + Bank End + Pos End + Hax Income + Hax Sold + Hax Balance OK? Actions @@ -15,8 +21,14 @@ {{ pr.date }} {{ pr.pos.name }} - {{ pr.bank_responsible }} - {{ pr.pos_responsible }} + Bank: {{ pr.bank_responsible }}
Pos: {{ pr.pos_responsible }} + {{ pr.bank_start_hax }} HAX / {{ pr.bank_count_dkk_start }} DKK + {{ pr.pos_start_hax }} HAX / {{ pr.pos_count_dkk_start }} DKK + {{ pr.bank_end_hax }} HAX / {{ pr.bank_count_dkk_end }} DKK + {{ pr.pos_end_hax }} HAX / {{ pr.pos_count_dkk_end }} DKK + {{ pr.pos_json_sales.1 }} HAX ({{ pr.pos_json_sales.0 }} tx) + {{ pr.hax_sold_izettle }} HAX + {{ pr.hax_balance }} HAX {{ pr.allok | truefalseicon }}
diff --git a/src/backoffice/templates/posreport_detail.html b/src/backoffice/templates/posreport_detail.html index 1093b526..6d74ba6e 100644 --- a/src/backoffice/templates/posreport_detail.html +++ b/src/backoffice/templates/posreport_detail.html @@ -55,6 +55,14 @@ PosReport {{ posreport.date }} {{ posreport.pos.name }} | Pos | BackOffice | {{ All OK? {{ posreport.allok | truefalseicon }}

+ + Hax Sold from iZettle + {{ posreport.hax_sold_izettle }} HAX + + + Hax Balance (we want 0 here) + {{ posreport.hax_balance }} HAX + Comments {{ posreport.comments }} @@ -134,7 +142,7 @@ PosReport {{ posreport.date }} {{ posreport.pos.name }} | Pos | BackOffice | {{ POS JSON - {{ posreport.pos_json }}

+ {{ posreport.pos_json_sales.1 }} HAX in {{ posreport.pos_json_sales.0 }} transactions

diff --git a/src/backoffice/views.py b/src/backoffice/views.py index 9331c1ce..f46818e5 100644 --- a/src/backoffice/views.py +++ b/src/backoffice/views.py @@ -2071,7 +2071,13 @@ class PosReportUpdateView(PosViewMixin, UpdateView): """Use this view to update PosReports.""" model = PosReport - fields = ["date", "bank_responsible", "pos_responsible", "comments"] + fields = [ + "date", + "bank_responsible", + "pos_responsible", + "hax_sold_izettle", + "comments", + ] template_name = "posreport_form.html" pk_url_kwarg = "posreport_uuid" diff --git a/src/economy/migrations/0016_posreport_hax_sold_izettle.py b/src/economy/migrations/0016_posreport_hax_sold_izettle.py new file mode 100644 index 00000000..a9875431 --- /dev/null +++ b/src/economy/migrations/0016_posreport_hax_sold_izettle.py @@ -0,0 +1,21 @@ +# Generated by Django 3.1 on 2020-09-02 20:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("economy", "0015_auto_20200813_2345"), + ] + + operations = [ + migrations.AddField( + model_name="posreport", + name="hax_sold_izettle", + field=models.PositiveIntegerField( + default=0, + help_text="The number of HAX sold through the iZettle from the POS", + ), + ), + ] diff --git a/src/economy/models.py b/src/economy/models.py index 774df5f1..e09cb9ac 100644 --- a/src/economy/models.py +++ b/src/economy/models.py @@ -555,6 +555,10 @@ class PosReport(CampRelatedModel, UUIDModel): blank=True, help_text="Any comments about this PosReport", ) + hax_sold_izettle = models.PositiveIntegerField( + default=0, help_text="The number of HAX sold through the iZettle from the POS", + ) + # bank count start of day bank_count_dkk_start = models.PositiveIntegerField( @@ -723,6 +727,46 @@ class PosReport(CampRelatedModel, UUIDModel): def hax100_start_ok(self): return self.bank_count_hax100_start == self.pos_count_hax100_start + @property + def bank_start_hax(self): + return ( + (self.bank_count_hax5_start * 5) + + (self.bank_count_hax10_start * 10) + + (self.bank_count_hax20_start * 20) + + (self.bank_count_hax50_start * 50) + + (self.bank_count_hax100_start * 100) + ) + + @property + def pos_start_hax(self): + return ( + (self.pos_count_hax5_start * 5) + + (self.pos_count_hax10_start * 10) + + (self.pos_count_hax20_start * 20) + + (self.pos_count_hax50_start * 50) + + (self.pos_count_hax100_start * 100) + ) + + @property + def bank_end_hax(self): + return ( + (self.bank_count_hax5_end * 5) + + (self.bank_count_hax10_end * 10) + + (self.bank_count_hax20_end * 20) + + (self.bank_count_hax50_end * 50) + + (self.bank_count_hax100_end * 100) + ) + + @property + def pos_end_hax(self): + return ( + (self.pos_count_hax5_end * 5) + + (self.pos_count_hax10_end * 10) + + (self.pos_count_hax20_end * 20) + + (self.pos_count_hax50_end * 50) + + (self.pos_count_hax100_end * 100) + ) + @property def dkk_end_ok(self): return self.bank_count_dkk_end == self.pos_count_dkk_end @@ -747,7 +791,6 @@ class PosReport(CampRelatedModel, UUIDModel): def hax100_end_ok(self): return self.bank_count_hax100_end == self.pos_count_hax100_end - @property def allok(self): return all( [ @@ -765,3 +808,28 @@ class PosReport(CampRelatedModel, UUIDModel): self.hax100_end_ok, ] ) + + @property + def pos_json_sales(self): + """Calculate the total HAX sales and number of transactions.""" + transactions = 0 + total = 0 + for tx in self.pos_json: + transactions += 1 + total += tx["amount"] + return transactions, total + + @property + def hax_balance(self): + """Return the hax balance all things considered.""" + balance = 0 + # start by adding what the POS got at the start of the day + balance += self.bank_start_hax + # then substract the HAX the POS sold via the izettle + balance -= self.hax_sold_izettle + # then add the HAX sales from the POS json + balance += self.pos_json_sales[1] + # finally substract the HAX received from the POS at the end of the day + balance -= self.bank_end_hax + # all good + return balance