diff --git a/ledger_pyreport/__init__.py b/ledger_pyreport/__init__.py index 3f572d5..6b87753 100644 --- a/ledger_pyreport/__init__.py +++ b/ledger_pyreport/__init__.py @@ -97,7 +97,7 @@ def balance(): balance_sheets = [accounting.balance_sheet(accounting.add_unrealized_gains(accounting.trial_balance(l, d, p), report_currency)) for d, p in zip(dates, pstarts)] # Delete accounts with always zero balances - accounts = sorted(l.accounts.values(), key=lambda a: a.name) + accounts = list(l.accounts.values()) for account in accounts[:]: if all(b.get_balance(account) == 0 and b.get_total(account) == 0 for b in balance_sheets): accounts.remove(account) @@ -129,7 +129,7 @@ def pandl(): pandls = [accounting.trial_balance(l, de, db) for de, db in zip(dates_end, dates_beg)] # Delete accounts with always zero balances - accounts = sorted(l.accounts.values(), key=lambda a: a.name) + accounts = list(l.accounts.values()) for account in accounts[:]: if all(p.get_balance(account) == 0 and p.get_total(account) == 0 for p in pandls): accounts.remove(account) diff --git a/ledger_pyreport/jinja2/balance.html b/ledger_pyreport/jinja2/balance.html index fc88f41..747d7cf 100644 --- a/ledger_pyreport/jinja2/balance.html +++ b/ledger_pyreport/jinja2/balance.html @@ -49,13 +49,13 @@ {% endfor %} - {% for child in account.children if child in accounts %} + {% for child in account.children|sort(attribute='name') if child in accounts %} {{ print_rows(child, invert, level + 1) }} {% endfor %} {% endmacro %} {% macro do_accounts(root, label, invert, year_headers) %} - {% for account_class in root.children if account_class in accounts %} + {% for account_class in root.children|sort(attribute='name') if account_class in accounts %} {% if loop.first and year_headers %} {{ account_class.bits[-1] }} {{ label }} @@ -65,7 +65,7 @@ {% endif %} - {% for account in account_class.children if account in accounts %} + {% for account in account_class.children|sort(attribute='name') if account in accounts %} {{ print_rows(account, invert=invert) }} {% endfor %} @@ -104,7 +104,7 @@ {# Equity #} Equity - {% for account in ledger.get_account(config['equity_account']).children if account in accounts %} + {% for account in ledger.get_account(config['equity_account']).children|sort(attribute='name') if account in accounts %} {{ print_rows(account, invert=True) }} {% endfor %} diff --git a/ledger_pyreport/jinja2/pandl.html b/ledger_pyreport/jinja2/pandl.html index 1f14fef..ecc484c 100644 --- a/ledger_pyreport/jinja2/pandl.html +++ b/ledger_pyreport/jinja2/pandl.html @@ -33,7 +33,7 @@ {% endfor %} - {% for child in account.children if child in accounts %} + {% for child in account.children|sort(attribute='name') if child in accounts %} {{ print_rows(child, invert, level + 1) }} {% endfor %} {% endmacro %} @@ -49,7 +49,7 @@ {% endif %} - {% for account in root.children if account in accounts %} + {% for account in root.children|sort(attribute='name') if account in accounts %} {{ print_rows(account, invert=invert) }} {% endfor %}