# In this scheme, negative numbers represent money the house owes
# the user, and positive numbers represent money the user owes the
# house
# In this scheme, negative numbers represent money the house owes
# the user, and positive numbers represent money the user owes the
# house
# Next, debit everyone for expenditures that they have an
# investment in (i.e. splits)
# Next, debit everyone for expenditures that they have an
# investment in (i.e. splits)
add_column(sqlalchemy.func.sum(model.Split.share).label('total_split')).\
group_by(model.Split.user_id)
for split, total_cents in total_splits:
add_column(sqlalchemy.func.sum(model.Split.share).label('total_split')).\
group_by(model.Split.user_id)
for split, total_cents in total_splits:
# Finally, move transfers around appropriately
#
# To keep this from getting to be expensive, have SQL sum up
# transfers for us
# Finally, move transfers around appropriately
#
# To keep this from getting to be expensive, have SQL sum up
# transfers for us
add_column(sqlalchemy.func.sum(model.Transfer.amount).label('total_amount'))
total_debits = transfer_q.group_by(model.Transfer.debtor_id)
total_credits = transfer_q.group_by(model.Transfer.creditor_id)
for transfer, total_amount in total_debits:
add_column(sqlalchemy.func.sum(model.Transfer.amount).label('total_amount'))
total_debits = transfer_q.group_by(model.Transfer.debtor_id)
total_credits = transfer_q.group_by(model.Transfer.creditor_id)
for transfer, total_amount in total_debits:
owes_list = [debt for debt in debts_list if debt['amount'] > 0]
owed_list = [debt for debt in debts_list if debt['amount'] < 0]
owes_list = [debt for debt in debts_list if debt['amount'] > 0]
owed_list = [debt for debt in debts_list if debt['amount'] < 0]
if len(owes_list) > 0:
raise DirtyBooks, ("People still owe money", owes_list)
if len(owed_list) > 0:
raise DirtyBooks, ("People are still owed money", owed_list)
if len(owes_list) > 0:
raise DirtyBooks, ("People still owe money", owes_list)
if len(owed_list) > 0:
raise DirtyBooks, ("People are still owed money", owed_list)