diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 250f009b..88762b85 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -6,6 +6,7 @@ from flask import g, current_app from debts import settle from sqlalchemy import orm +from sqlalchemy.sql import func from itsdangerous import ( TimedJSONWebSignatureSerializer, URLSafeSerializer, @@ -376,8 +377,10 @@ class Bill(db.Model): def pay_each(self): """Compute what each share has to pay""" if self.owers: - # FIXME: SQL might do that more efficiently - weights = sum(i.weight for i in self.owers) + weights = (db.session.query(func.sum(Person.weight)) + .join(billowers, Bill) + .filter(Bill.id == self.id))\ + .scalar() return self.amount / weights else: return 0 diff --git a/ihatemoney/templates/forms.html b/ihatemoney/templates/forms.html index 95606e5d..cd532433 100644 --- a/ihatemoney/templates/forms.html +++ b/ihatemoney/templates/forms.html @@ -112,7 +112,12 @@ diff --git a/ihatemoney/web.py b/ihatemoney/web.py index be39feb8..928174dd 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -699,7 +699,6 @@ def delete_bill(bill_id): @main.route("//edit/", methods=["GET", "POST"]) def edit_bill(bill_id): - # FIXME: Test this bill belongs to this project ! bill = Bill.query.get(g.project, bill_id) if not bill: raise NotFound()