diff options
| author | Alexis Metaireau <alexis@notmyidea.org> | 2011-10-18 23:26:13 +0200 |
|---|---|---|
| committer | Alexis Metaireau <alexis@notmyidea.org> | 2011-10-18 23:26:13 +0200 |
| commit | 6f4f04b11756086fa4ace404d4f00c856dc6f157 (patch) | |
| tree | c5cb1261cb570a6ef59e0fb76279dc2949196eda /budget | |
| parent | 4e1819523f50114ce5e3f0524fc27eb85701da37 (diff) | |
| download | ihatemoney-mirror-6f4f04b11756086fa4ace404d4f00c856dc6f157.zip ihatemoney-mirror-6f4f04b11756086fa4ace404d4f00c856dc6f157.tar.gz ihatemoney-mirror-6f4f04b11756086fa4ace404d4f00c856dc6f157.tar.bz2 | |
Document the API. Fix #46
Diffstat (limited to 'budget')
| -rw-r--r-- | budget/models.py | 7 | ||||
| -rw-r--r-- | budget/templates/list_bills.html | 8 | ||||
| -rw-r--r-- | budget/tests.py | 14 |
3 files changed, 15 insertions, 14 deletions
diff --git a/budget/models.py b/budget/models.py index e5d5ea9..152ad34 100644 --- a/budget/models.py +++ b/budget/models.py @@ -12,7 +12,7 @@ db = SQLAlchemy() class Project(db.Model): _to_serialize = ("id", "name", "password", "contact_email", - "members", "active_members") + "members", "active_members", "balance") id = db.Column(db.String, primary_key=True) @@ -25,7 +25,8 @@ class Project(db.Model): def active_members(self): return [m for m in self.members if m.activated] - def get_balance(self): + @property + def balance(self): balances, should_pay, should_receive = defaultdict(int), defaultdict(int), defaultdict(int) @@ -39,7 +40,7 @@ class Project(db.Model): should_receive[bill.payer] += bill.pay_each() for person in self.members: - balances[person] = round(should_receive[person] - should_pay[person], 2) + balances[person.id] = round(should_receive[person] - should_pay[person], 2) return balances diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html index d163f7e..e284eff 100644 --- a/budget/templates/list_bills.html +++ b/budget/templates/list_bills.html @@ -56,13 +56,13 @@ <h2>{{ _("Balance") }}</h2> <table class="balance"> - {% set balance = g.project.get_balance() %} + {% set balance = g.project.balance %} {% for member in g.project.members %} - {% if member.activated or balance[member] != 0 %} + {% if member.activated or balance[member.id] != 0 %} <tr> <td>{{ member.name }}</td> - <td class="{% if balance[member] > 0 %}positive{% elif balance[member] < 0 %}negative{% endif %}"> - {% if balance[member] > 0 %}+{% endif %}{{ balance[member] }} + <td class="{% if balance[member.id] > 0 %}positive{% elif balance[member.id] < 0 %}negative{% endif %}"> + {% if balance[member.id] > 0 %}+{% endif %}{{ balance[member.id] }} </td> <td> {% if member.activated %}<a class="remove" href="{{ url_for(".remove_member", member_id=member.id) }}">{{ _("delete") }}</a>{% else %}<a href="{{ url_for(".reactivate", member_id=member.id) }}">{{ _("reactivate") }}</a>{% endif %}</td> </tr> diff --git a/budget/tests.py b/budget/tests.py index 452f71f..3f261fa 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -333,7 +333,7 @@ class BudgetTestCase(TestCase): 'amount': '17', }) - balance = models.Project.query.get("raclette").get_balance() + balance = models.Project.query.get("raclette").balance self.assertEqual(set(balance.values()), set([19.0, -19.0])) def test_rounding(self): @@ -369,10 +369,8 @@ class BudgetTestCase(TestCase): 'amount': '22', }) - balance = models.Project.query.get("raclette").get_balance() - balance = dict([(user.name, bal) for user, bal in balance.items()]) - self.assertDictEqual(balance, {u'tata': -8.12, u'alexis': 8.12, - u'fred': 0.0}) + balance = models.Project.query.get("raclette").balance + self.assertDictEqual(balance, {3: -8.12, 1: 8.12, 2: 0.0}) def test_edit_project(self): @@ -489,7 +487,8 @@ class APITestCase(TestCase): "contact_email": "raclette@notmyidea.org", "members": [], "password": "raclette", - "id": "raclette" + "id": "raclette", + "balance": {}, } self.assertDictEqual(json.loads(resp.data), expected) @@ -512,7 +511,8 @@ class APITestCase(TestCase): "contact_email": "yeah@notmyidea.org", "members": [], "password": "raclette", - "id": "raclette" + "id": "raclette", + "balance": {}, } self.assertDictEqual(json.loads(resp.data), expected) |
