예제 #1
0
 def get(self):
     res = []
     for t in Transaction.unreconciled(db_session).order_by(
             Transaction.date).all():
         d = t.as_dict
         d['budgets'] = [{
             'name': bt.budget.name,
             'id': bt.budget_id,
             'amount': bt.amount,
             'is_income': bt.budget.is_income
         } for bt in sorted(
             t.budget_transactions, key=lambda x: x.amount, reverse=True)]
         d['account_name'] = t.account.name
         res.append(d)
     return jsonify(res)
예제 #2
0
 def test_unreconciled(self):
     Transaction()
     m_db = Mock()
     m_q = Mock(spec_set=Query)
     m_filt = Mock(spec_set=Query)
     m_db.query.return_value = m_q
     m_q.filter.return_value = m_filt
     res = Transaction.unreconciled(m_db)
     assert res == m_filt
     assert len(m_db.mock_calls) == 2
     assert m_db.mock_calls[0] == call.query(Transaction)
     kall = m_db.mock_calls[1]
     assert kall[0] == 'query().filter'
     expected1 = Transaction.reconcile.__eq__(null())
     expected2 = Transaction.date.__ge__(date(2017, 3, 17))
     expected3 = Transaction.account.has(reconcile_trans=True)
     assert len(kall[1]) == 3
     assert str(expected1) == str(kall[1][0])
     assert binexp_to_dict(expected2) == binexp_to_dict(kall[1][1])
     assert str(expected3) == str(kall[1][2])