Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1650 from gittip/fix-exchanges-bug
Browse files Browse the repository at this point in the history
Fix bug in record-an-exchange; #1633
  • Loading branch information
seanlinsley committed Nov 8, 2013
2 parents e61cef1 + e47d207 commit 5b888f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ blacklisted or whitelisted user.
* blacklisted cannot do anything


The exchanges table records movements of money into and out of Gittip. The
``amount`` column shows a positive amount for payins and a negative amount for
payouts. The ``fee`` column is always positive. For both payins and payouts,
the ``amount`` does not include the ``fee`` (e.g., a $10 payin would result in
an ``amount`` of ``9.41`` and a ``fee`` of ``0.59``, and a $100 payout with a
2% fee would result in an ``amount`` of ``-98.04`` and a fee of ``1.96``).


Contents
--------
Expand Down
7 changes: 7 additions & 0 deletions tests/test_record_an_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ def test_withdrawals_work(self):
SQL = "SELECT balance FROM participants WHERE username='bob'"
actual = self.db.one(SQL)
assert actual == expected

def test_withdrawals_take_fee_out_of_balance(self):
self.make_participant('alice', claimed_time=utcnow(), is_admin=True)
self.make_participant('bob', claimed_time=utcnow(), balance=20)
self.record_an_exchange('-7', '1.13', 'noted', False)
SQL = "SELECT balance FROM participants WHERE username='bob'"
assert self.db.one(SQL) == Decimal('11.87')
10 changes: 9 additions & 1 deletion www/%username/history/record-an-exchange.spt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ with gittip.db.get_cursor() as cursor:
"VALUES (%s, %s, %s, %s, %s)"
cursor.execute(SQL, params)

if amount < 0:
# For payouts, we need to take the fee out of their Gittip balance.
balance_adjustment = amount - fee
else:
# For payins, we don't have to worry about the fee relative to their
# balance, because the amount is already less the fee.
balance_adjustment = amount

SQL = "UPDATE participants SET balance = balance + %s WHERE username=%s"
cursor.execute(SQL, (amount, participant.username))
cursor.execute(SQL, (balance_adjustment, participant.username))

request.redirect('/%s/history/' % participant.username)

Expand Down

0 comments on commit 5b888f0

Please sign in to comment.