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

Commit

Permalink
Add docs for utils/history.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed May 3, 2017
1 parent 8f6dac5 commit 8e96650
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gratipay/utils/history.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""Helpers to fetch logs of payments made to/from a participant.
There are three different tables that we pull data from:
- `transfers`: Used under Gratipay 1.0, when users were allowed to tip
each other (without having to setup a team). `transfers` models
money moving *within* Gratipay, from one participant (`tipper`)
to another (`tippee`).
- `payments`: The replacement for `transfers`, used in Gratipay 2.0. `payments`
are between a Team and a Participant, in either direction (`to-team`,
or `to-participant`)
- `exchanges`: Records money moving in and out of Gratipay. Every `exchange` is linked
to a participant. The `amount` is +ve for money flowing *into* gratipay,
and -ve for money flowing *out* of Gratipay
"""

from datetime import datetime
from decimal import Decimal

Expand All @@ -23,6 +39,8 @@ def get_end_of_year_balance(db, participant, year, current_year):

username = participant.username
start_balance = get_end_of_year_balance(db, participant, year-1, current_year)

# FIXME - delta from the `payments` table should be included too!
delta = db.one("""
SELECT (
SELECT COALESCE(sum(amount), 0) AS a
Expand Down Expand Up @@ -164,6 +182,8 @@ def export_history(participant, year, mode, key, back_as='namedtuple', require_k
db = participant.db
params = dict(username=participant.username, year=year)
out = {}

# FIXME - values from the `payments` table should be included too!
if mode == 'aggregate':
out['given'] = lambda: db.all("""
SELECT tippee, sum(amount) AS amount
Expand Down Expand Up @@ -212,6 +232,8 @@ def export_history(participant, year, mode, key, back_as='namedtuple', require_k
ORDER BY timestamp ASC
""", params, back_as=back_as)

import pdb; pdb.set_trace();

if key:
try:
return out[key]()
Expand Down

0 comments on commit 8e96650

Please sign in to comment.