From 2e7413a68fed37543e67c6e7b054f2bd62a9f931 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Thu, 23 Jun 2016 23:33:53 -0400 Subject: [PATCH] Add 'recently purchased items' to terminal --- chezbetty/models/transaction.py | 2 +- chezbetty/models/user.py | 15 ++++++++++++ chezbetty/static/js/chezbetty-terminal.js | 6 +++++ chezbetty/templates/terminal/terminal.jinja2 | 25 +++++++++++++++++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/chezbetty/models/transaction.py b/chezbetty/models/transaction.py index e5972d7..b55d6da 100644 --- a/chezbetty/models/transaction.py +++ b/chezbetty/models/transaction.py @@ -301,7 +301,7 @@ def __get_events(self): @property def __events(self): - return __get_events(self).all() + return __get_events(self) account.Account.get_events = __get_events account.Account.events = __events diff --git a/chezbetty/models/user.py b/chezbetty/models/user.py index d17bb64..7ec42e8 100644 --- a/chezbetty/models/user.py +++ b/chezbetty/models/user.py @@ -258,6 +258,21 @@ def get_user_count_cumulative(cls): .all() return utility.timeseries_cumulative(rows) + def iterate_recent_items(self, limit=None, allow_duplicates=False): + items = set() + count = 0 + for e in self.events: + if e.type == 'purchase': + for transaction in e.transactions: + if transaction.type == 'purchase': + for line_item in transaction.subtransactions: + if (line_item.item not in items) or allow_duplicates: + count += 1 + if limit is not None and count > limit: + return + yield line_item.item + items.add(line_item.item) + def __make_salt(self): return binascii.b2a_base64(open("/dev/urandom", "rb").read(32))[:-3].decode("ascii") diff --git a/chezbetty/static/js/chezbetty-terminal.js b/chezbetty/static/js/chezbetty-terminal.js index 1fd97ad..1afe006 100644 --- a/chezbetty/static/js/chezbetty-terminal.js +++ b/chezbetty/static/js/chezbetty-terminal.js @@ -756,6 +756,12 @@ $('#tag-items').on('click', '.tag-item', function () { $('#panel-purchase').show(); }); +$('#recently-purchased').on('click', '.tag-item', function () { + console.log($(this)); + var item_id = $(this).attr('data-item-id'); + add_item_id(item_id); +}); + // DEPOSIT // Called to let the user know we got the bill, we just need time to count it. diff --git a/chezbetty/templates/terminal/terminal.jinja2 b/chezbetty/templates/terminal/terminal.jinja2 index 1032f1e..b607a71 100644 --- a/chezbetty/templates/terminal/terminal.jinja2 +++ b/chezbetty/templates/terminal/terminal.jinja2 @@ -262,8 +262,31 @@ + {# Recently purchased items #} +
+

Quick-Select Most Recently Purchased Items

+
+
+ {% for item in user.iterate_recent_items(limit=5) %} +
+
+ {% if item.img %} + + {% else %} + + {% endif %} +
+ {{ item.name }} +
+
+
+ {% endfor %} +
+ +
+ {# Purchase buttons #} -
+