Skip to content

Commit

Permalink
Add 'recently purchased items' to terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
ppannuto committed Jun 24, 2016
1 parent 80f1b6a commit 2e7413a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chezbetty/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions chezbetty/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 6 additions & 0 deletions chezbetty/static/js/chezbetty-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 24 additions & 1 deletion chezbetty/templates/terminal/terminal.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,31 @@
</div>
</div>

{# Recently purchased items #}
<hr />
<h4>Quick-Select Most Recently Purchased Items</h4>
<div id="recently-purchased" class="row">
<div class="col-md-1"></div>
{% for item in user.iterate_recent_items(limit=5) %}
<div class="col-md-2">
<div class="tag-item" data-item-id="{{ item.id }}">
{% if item.img %}
<img src="/dynamic/item/{{item.id}}.jpg" width="150px" />
{% else %}
<img src="{{'chezbetty:static/placeholder_300px.png'|static_url}}" width="150px" />
{% endif %}
<div class="tag-item-name">
{{ item.name }}
</div>
</div>
</div>
{% endfor %}
</div>

<hr />

{# Purchase buttons #}
<div class="row">
<div id="purchase-buttons" class="row">
<div class="col-md-12">
<button type="button" id="purchase-button-logout" class="btn btn-success btn-lg btn-submit btn-submit-purchase">{{ _('Logout') }}</button>
<button type="button" id="purchase-button-purchaselogout" class="btn btn-success btn-lg btn-submit btn-submit-purchase" style="display:none;">{{ _('Purchase & Logout') }}</button>
Expand Down

0 comments on commit 2e7413a

Please sign in to comment.