Sort accounts by name in balance sheet and P&L

This commit is contained in:
RunasSudo 2020-03-23 00:51:13 +11:00
parent 1ce132d4b0
commit bbd99af710
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 8 additions and 8 deletions

View File

@ -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)] 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 # 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[:]: for account in accounts[:]:
if all(b.get_balance(account) == 0 and b.get_total(account) == 0 for b in balance_sheets): if all(b.get_balance(account) == 0 and b.get_total(account) == 0 for b in balance_sheets):
accounts.remove(account) 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)] pandls = [accounting.trial_balance(l, de, db) for de, db in zip(dates_end, dates_beg)]
# Delete accounts with always zero balances # 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[:]: for account in accounts[:]:
if all(p.get_balance(account) == 0 and p.get_total(account) == 0 for p in pandls): if all(p.get_balance(account) == 0 and p.get_total(account) == 0 for p in pandls):
accounts.remove(account) accounts.remove(account)

View File

@ -49,13 +49,13 @@
{% endfor %} {% endfor %}
</tr> </tr>
{% 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) }} {{ print_rows(child, invert, level + 1) }}
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
{% macro do_accounts(root, label, invert, year_headers) %} {% 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 %}
<tr> <tr>
{% if loop.first and year_headers %} {% if loop.first and year_headers %}
<th class="h2">{{ account_class.bits[-1] }} {{ label }}</th> <th class="h2">{{ account_class.bits[-1] }} {{ label }}</th>
@ -65,7 +65,7 @@
{% endif %} {% endif %}
</tr> </tr>
{% 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) }} {{ print_rows(account, invert=invert) }}
{% endfor %} {% endfor %}
@ -104,7 +104,7 @@
{# Equity #} {# Equity #}
<tr><th class="h1" colspan="{{ balance_sheets|length + 1 }}">Equity</th></tr> <tr><th class="h1" colspan="{{ balance_sheets|length + 1 }}">Equity</th></tr>
{% 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) }} {{ print_rows(account, invert=True) }}
{% endfor %} {% endfor %}

View File

@ -33,7 +33,7 @@
{% endfor %} {% endfor %}
</tr> </tr>
{% 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) }} {{ print_rows(child, invert, level + 1) }}
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
@ -49,7 +49,7 @@
{% endif %} {% endif %}
</tr> </tr>
{% 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) }} {{ print_rows(account, invert=invert) }}
{% endfor %} {% endfor %}