Skip to content

Commit

Permalink
don't merge manual deposits
Browse files Browse the repository at this point in the history
note: this isn't perfect, as a manual deposit followed by bill acceptor
deposit will still get merged.
  • Loading branch information
bradjc committed May 22, 2016
1 parent 2b11ba0 commit 53172e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions chezbetty/datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ def purchase(user, account, items):

# Call this when a user puts money in the dropbox and needs to deposit it
# to their account
# If `merge==True`, then try to squash multiple deposits in a row together
@top_debtor_wrapper
def deposit(user, account, amount):
def deposit(user, account, amount, merge=True):
assert(amount > 0.0)
assert(hasattr(user, "id"))

Expand All @@ -264,15 +265,16 @@ def deposit(user, account, amount):

# Get recent deposits that we might merge with this one
events_to_delete = []
recent_deposits = event.Deposit.get_user_recent(user)
for d in recent_deposits:
# Only look at transaction events with 1 CashDeposit transaction
if len(d.transactions) == 1 and d.transactions[0].type == 'cashdeposit':
t = d.transactions[0]
# Must be a deposit to the same account
if t.to_account_virt_id == account.id:
deposit_total += t.amount
events_to_delete.append(d)
if merge:
recent_deposits = event.Deposit.get_user_recent(user)
for d in recent_deposits:
# Only look at transaction events with 1 CashDeposit transaction
if len(d.transactions) == 1 and d.transactions[0].type == 'cashdeposit':
t = d.transactions[0]
# Must be a deposit to the same account
if t.to_account_virt_id == account.id:
deposit_total += t.amount
events_to_delete.append(d)


# TODO (added on 2016/05/14): Make adding the new deposit and deleting
Expand Down
1 change: 1 addition & 0 deletions chezbetty/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get_user_recent(cls, user):
.filter(cls.user_id == user.id)\
.filter(cls.timestamp>=(datetime.datetime.utcnow()-datetime.timedelta(minutes=2)))\
.filter(cls.deleted == False)\
.limit(1)\
.all()


Expand Down
2 changes: 1 addition & 1 deletion chezbetty/views_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def terminal_deposit(request):
ret = {}

if user:
deposit = datalayer.deposit(user, user, amount)
deposit = datalayer.deposit(user, user, amount, method != 'manual')
ret['type'] = 'user'
ret['amount'] = float(deposit['amount'])
ret['event_id'] = deposit['event'].id
Expand Down

0 comments on commit 53172e5

Please sign in to comment.