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:
parent
058cc8a9e5
commit
ff9ead2203
1 changed files with 6 additions and 4 deletions
|
@ -51,13 +51,15 @@ class Project(db.Model):
|
||||||
|
|
||||||
def get_transactions_to_settle_bill(self):
|
def get_transactions_to_settle_bill(self):
|
||||||
"""Return a list of transactions that could be made to settle the bill"""
|
"""Return a list of transactions that could be made to settle the bill"""
|
||||||
|
#cache value for better performance
|
||||||
|
balance = self.balance
|
||||||
credits, debts, transactions = [],[],[]
|
credits, debts, transactions = [],[],[]
|
||||||
# Create lists of credits and debts
|
# Create lists of credits and debts
|
||||||
for person in self.members:
|
for person in self.members:
|
||||||
if self.balance[person.id] > 0:
|
if balance[person.id] > 0:
|
||||||
credits.append({"person": person, "balance": self.balance[person.id]})
|
credits.append({"person": person, "balance": balance[person.id]})
|
||||||
elif self.balance[person.id] < 0:
|
elif balance[person.id] < 0:
|
||||||
debts.append({"person": person, "balance": -self.balance[person.id]})
|
debts.append({"person": person, "balance": -balance[person.id]})
|
||||||
# Try and find exact matches
|
# Try and find exact matches
|
||||||
for credit in credits:
|
for credit in credits:
|
||||||
match = self.exactmatch(credit["balance"], debts)
|
match = self.exactmatch(credit["balance"], debts)
|
||||||
|
|
Loading…
Add table
Reference in a new issue