diff options
| author | A.Avenel <avenel.alexandre@gmail.com> | 2013-05-09 23:23:23 +0200 |
|---|---|---|
| committer | A.Avenel <avenel.alexandre@gmail.com> | 2013-05-09 23:23:23 +0200 |
| commit | ff9ead22031563b31f14e87ae3b3c537a06b8c41 (patch) | |
| tree | 26f5304e3321c3505894020ad9c93cc3eed8daa2 /budget | |
| parent | 058cc8a9e5c5d06bd3aedeff4de782907b014d50 (diff) | |
| download | ihatemoney-mirror-ff9ead22031563b31f14e87ae3b3c537a06b8c41.zip ihatemoney-mirror-ff9ead22031563b31f14e87ae3b3c537a06b8c41.tar.gz ihatemoney-mirror-ff9ead22031563b31f14e87ae3b3c537a06b8c41.tar.bz2 | |
Optimization
Diffstat (limited to 'budget')
| -rw-r--r-- | budget/models.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/budget/models.py b/budget/models.py index 49c3eb4..2d44145 100644 --- a/budget/models.py +++ b/budget/models.py @@ -51,13 +51,15 @@ class Project(db.Model): def get_transactions_to_settle_bill(self): """Return a list of transactions that could be made to settle the bill""" + #cache value for better performance + balance = self.balance credits, debts, transactions = [],[],[] # Create lists of credits and debts for person in self.members: - if self.balance[person.id] > 0: - credits.append({"person": person, "balance": self.balance[person.id]}) - elif self.balance[person.id] < 0: - debts.append({"person": person, "balance": -self.balance[person.id]}) + if balance[person.id] > 0: + credits.append({"person": person, "balance": balance[person.id]}) + elif balance[person.id] < 0: + debts.append({"person": person, "balance": -balance[person.id]}) # Try and find exact matches for credit in credits: match = self.exactmatch(credit["balance"], debts) |
