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):
"""
# 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)
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
#
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