diff options
| author | Jocelyn Delande <jocelyn@crapouillou.net> | 2015-08-20 10:33:43 +0200 |
|---|---|---|
| committer | Jocelyn Delande <jocelyn@crapouillou.net> | 2016-06-15 10:20:37 +0200 |
| commit | 2b071a1a3bc752bfaa0fd6c0b2d8f8460721d6d8 (patch) | |
| tree | 72fcca608854117b3d87de95454f88bbb9260dd9 /budget/models.py | |
| parent | 789196721584ca4800e4236eee36955e78761346 (diff) | |
| download | ihatemoney-mirror-2b071a1a3bc752bfaa0fd6c0b2d8f8460721d6d8.zip ihatemoney-mirror-2b071a1a3bc752bfaa0fd6c0b2d8f8460721d6d8.tar.gz ihatemoney-mirror-2b071a1a3bc752bfaa0fd6c0b2d8f8460721d6d8.tar.bz2 | |
Add members weight in models and budget backend refs #94
Diffstat (limited to 'budget/models.py')
| -rw-r--r-- | budget/models.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/budget/models.py b/budget/models.py index 727200f..16cc6c1 100644 --- a/budget/models.py +++ b/budget/models.py @@ -40,8 +40,9 @@ class Project(db.Model): bills = Bill.query.filter(Bill.owers.contains(person)) for bill in bills.all(): if person != bill.payer: - should_pay[person] += bill.pay_each() - should_receive[bill.payer] += bill.pay_each() + share = bill.pay_each() * person.weight + should_pay[person] += share + should_receive[bill.payer] += share for person in self.members: balance = should_receive[person] - should_pay[person] @@ -159,6 +160,7 @@ class Person(db.Model): bills = db.relationship("Bill", backref="payer") name = db.Column(db.UnicodeText) + weight = db.Column(db.Float, default=1) activated = db.Column(db.Boolean, default=True) def has_bills(self): @@ -219,7 +221,8 @@ class Bill(db.Model): def pay_each(self): """Compute what each person has to pay""" if self.owers: - return self.amount / len(self.owers) + # FIXME: SQL might dot that more efficiently + return self.amount / sum(i.weight for i in self.owers) else: return 0 |
