def add_fee(group, amount, payer_id, participants, date=None): fee = Fee(amount = amount, payer = get_user(payer_id), participants = participants, group = group,) if date: fee.date = date fee.put() return fee
def test_fees(self): fee = Fee(date=date(2011, 3, 15), amount=300.12) expected = (fee.date, -fee.amount) self.assertEqual([expected], map(cashflow_to_tuple, fees_to_cashflows(date(2011, 3, 15), [fee])), "nominal") self.assertSequenceEqual([], fees_to_cashflows(date(2011, 3, 14), [fee]), "fees are counted")
def get_fees(group): query = Fee.gql("WHERE group = :1 ORDER BY date DESC", group) raws = query.fetch(20) fees = [] for raw in raws: fee = {} fee['date'] = raw.date fee['id'] = raw.key().id() fee['spenders'] = [] average = raw.amount / len(raw.participants) for m in group.members: if m == raw.payer.key().id(): spender = {'amount': raw.amount -average, 'payer': True,} elif m in raw.participants: spender = {'amount': -average,} else: spender = {'amount': 0,} fee['spenders'].append(spender) fees.append(fee) return fees
def get_fee(id): try: return Fee.get_by_id(long(id)) except: return None