1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Optimization

This commit is contained in:
A.Avenel 2013-05-09 23:23:23 +02:00
parent 058cc8a9e5
commit ff9ead2203

View file

@ -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)