From 20476e02310c2f855a1a157908e66dc8a58518a6 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Thu, 18 Jan 2024 13:37:47 +0000 Subject: [PATCH] Add page showing all transactions in a datatable Remove the "Deferred transactions" page because it is now redundant. --- quicktill/tillweb/datatable.py | 21 +++-- .../tillweb/templates/tillweb/index.html | 2 +- .../tillweb/templates/tillweb/tillweb.html | 12 ++- .../tillweb/transactions-deferred.html | 36 -------- .../templates/tillweb/transactions.html | 85 +++++++++++++++++++ quicktill/tillweb/urls.py | 3 +- quicktill/tillweb/views.py | 15 +--- 7 files changed, 115 insertions(+), 59 deletions(-) delete mode 100644 quicktill/tillweb/templates/tillweb/transactions-deferred.html create mode 100644 quicktill/tillweb/templates/tillweb/transactions.html diff --git a/quicktill/tillweb/datatable.py b/quicktill/tillweb/datatable.py index 9db28848..595be099 100644 --- a/quicktill/tillweb/datatable.py +++ b/quicktill/tillweb/datatable.py @@ -128,6 +128,7 @@ def transactions(request, info): columns = { 'id': Transaction.id, 'sessionid': Transaction.sessionid, + 'session_date': Session.date, 'total': Transaction.total, 'discount_total': Transaction.discount_total, 'notes': Transaction.notes, @@ -144,11 +145,16 @@ def transactions(request, info): undefer('discount_total'), contains_eager(Transaction.session)) + # Searching by amount is slow across the entire table. Disable + # this if we are not filtering the table first. + enable_amount_search = False + # Apply filters from parameters. The 'unfiltered' item count for # this table is after this filtering step. try: sessionid = int(request.GET.get('sessionid')) q = q.filter(Session.id == sessionid) + enable_amount_search = True except (ValueError, TypeError): pass @@ -157,11 +163,12 @@ def transactions(request, info): fq = q state = request.GET.get('state', 'any') if state == "closed": - q = q.filter(Transaction.closed == True) + fq = fq.filter(Transaction.closed == True) elif state == "open": - q = q.filter(Transaction.closed == False) + fq = fq.filter(Transaction.closed == False)\ + .filter(Transaction.sessionid != None) elif state == "deferred": - q = q.filter(Transaction.sessionid == None) + fq = fq.filter(Transaction.sessionid == None) if search_value: try: intsearch = int(search_value) @@ -177,7 +184,7 @@ def transactions(request, info): if intsearch: qs.append(columns['id'] == intsearch) qs.append(columns['sessionid'] == intsearch) - if decsearch is not None: + if enable_amount_search and decsearch is not None: qs.append(columns['total'] == decsearch) qs.append(columns['discount_total'] == decsearch) fq = q.filter(or_(*qs)) @@ -186,9 +193,9 @@ def transactions(request, info): request, q, fq, columns, lambda t: { 'id': t.id, 'url': t.get_absolute_url(), - 'sessionid': t.session.id, - 'session_url': t.session.get_absolute_url(), - 'session_date': t.session.date, + 'sessionid': t.session.id if t.session else None, + 'session_url': t.session.get_absolute_url() if t.session else None, + 'session_date': t.session.date if t.session else None, 'total': t.total, 'discount_total': t.discount_total, 'notes': t.notes, diff --git a/quicktill/tillweb/templates/tillweb/index.html b/quicktill/tillweb/templates/tillweb/index.html index 1308e80f..44e3ee4c 100644 --- a/quicktill/tillweb/templates/tillweb/index.html +++ b/quicktill/tillweb/templates/tillweb/index.html @@ -16,7 +16,7 @@ {% endfor %}{% if currentsession.pending_total %}({{money}}{{currentsession.pending_total}} unpaid){% endif %} {% else %}No current session{% endif %} {% if deferred %} -
{{money}}{{deferred}} deferred transactions +
{{money}}{{deferred}} deferred transactions {% endif %} diff --git a/quicktill/tillweb/templates/tillweb/tillweb.html b/quicktill/tillweb/templates/tillweb/tillweb.html index e33935bd..a74e6426 100644 --- a/quicktill/tillweb/templates/tillweb/tillweb.html +++ b/quicktill/tillweb/templates/tillweb/tillweb.html @@ -79,7 +79,10 @@ if (data) { return "Closed"; } - return "Open"; + if (row["sessionid"]) { + return "Open"; + } + return "Deferred"; }; }; @@ -115,7 +118,12 @@