mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Round the balance. Fix #1
This commit is contained in:
parent
75209aeed0
commit
7d9fde0460
2 changed files with 40 additions and 1 deletions
|
@ -39,7 +39,7 @@ class Project(db.Model):
|
|||
should_receive[bill.payer] += bill.pay_each()
|
||||
|
||||
for person in self.members:
|
||||
balances[person] = should_receive[person] - should_pay[person]
|
||||
balances[person] = round(should_receive[person] - should_pay[person], 2)
|
||||
|
||||
return balances
|
||||
|
||||
|
|
|
@ -327,6 +327,45 @@ class BudgetTestCase(TestCase):
|
|||
balance = models.Project.query.get("raclette").get_balance()
|
||||
self.assertEqual(set(balance.values()), set([19.0, -19.0]))
|
||||
|
||||
def test_rounding(self):
|
||||
self.post_project("raclette")
|
||||
|
||||
# add members
|
||||
self.app.post("/raclette/members/add", data={'name': 'alexis' })
|
||||
self.app.post("/raclette/members/add", data={'name': 'fred' })
|
||||
self.app.post("/raclette/members/add", data={'name': 'tata' })
|
||||
|
||||
# create bills
|
||||
req = self.app.post("/raclette/add", data={
|
||||
'date': '2011-08-10',
|
||||
'what': u'fromage à raclette',
|
||||
'payer': 1,
|
||||
'payed_for': [1, 2, 3],
|
||||
'amount': '24.36',
|
||||
})
|
||||
|
||||
req2 = self.app.post("/raclette/add", data={
|
||||
'date': '2011-08-10',
|
||||
'what': u'red wine',
|
||||
'payer': 2,
|
||||
'payed_for': [1],
|
||||
'amount': '19.12',
|
||||
})
|
||||
|
||||
req3 = self.app.post("/raclette/add", data={
|
||||
'date': '2011-08-10',
|
||||
'what': u'delicatessen',
|
||||
'payer': 1,
|
||||
'payed_for': [1, 2],
|
||||
'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})
|
||||
|
||||
|
||||
def test_edit_project(self):
|
||||
# A project should be editable
|
||||
|
||||
|
|
Loading…
Reference in a new issue