autosort: Fix ZeroDivision bug when DB is empty

This commit is contained in:
fleaz 2020-03-30 21:57:47 +02:00
parent 851ecdbc57
commit bc832fd488

View file

@ -20,7 +20,10 @@ def command():
unsorted = session.query(Transaction).filter(Transaction.category_id == None).count()
transactions = session.query(Transaction).count()
categories = session.query(Category).count()
unsorted_percent = round(unsorted / (transactions / 100), 1)
try:
unsorted_percent = round(unsorted / (transactions / 100), 1)
except ZeroDivisionError:
unsorted_percent = 0
print(f"Transactions: {transactions}")
print(f" Unsorted: {unsorted} ({unsorted_percent}%)")