aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
Diffstat (limited to 'budget')
-rw-r--r--budget/models.py10
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)