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 @@
{{ _("Select all") }} | {{_("Select none")}}
{% for key, value, checked in form.payed_for.iter_choices() | sort(attribute='1') %} - ++ +
{% endfor %}