]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/lib/totals.py
Switch from using Decimal to using a new Currency class
[bluechips.git] / bluechips / lib / totals.py
index 3f18a32d115d46ddee1fce3017412074a6a5a6d5..53392c87060df3d7c5b303e3b256946331541f17 100644 (file)
@@ -5,9 +5,9 @@ Calculate the total state of the books
 from bluechips import model
 from bluechips.model import meta
 
-import sqlalchemy
+from bluechips.model.types import Currency
 
-from decimal import Decimal
+import sqlalchemy
 
 class DirtyBooks(Exception):
     """
@@ -25,7 +25,7 @@ def debts():
     
     # First, credit everyone for expenditures they've made
     for user in users:
-        debts[user] = -sum(map((lambda x: x.amount), user.expenditures))
+        debts[user] = Currency(-sum(map((lambda x: x.amount), user.expenditures)))
     
     # Next, debit everyone for expenditures that they have an
     # investment in (i.e. splits)
@@ -35,7 +35,7 @@ def debts():
         group_by(model.Split.user_id)
     
     for split, total_cents in total_splits:
-        debts[split.user] += (total_cents / 100)
+        debts[split.user] += total_cents
     
     # Finally, move transfers around appropriately
     #
@@ -48,9 +48,9 @@ def debts():
     total_credits = transfer_q.group_by(model.Transfer.creditor_id)
     
     for transfer, total_amount in total_debits:
-        debts[transfer.debtor] -= (total_amount / 100)
+        debts[transfer.debtor] -= total_amount
     for transfer, total_amount in total_credits:
-        debts[transfer.creditor] += (total_amount / 100)
+        debts[transfer.creditor] += total_amount
     
     return debts