{% import 'macros/_account_macros.html' as account_macros with context %} {% set show_other_column = (operating_currencies|length < ledger.options['commodities']|length) %} {% macro tree(real_account, totals=True) %}
  1. {% for currency in operating_currencies %} {{ currency }} {% endfor %} {% if show_other_column %} {{ _('Other') }} {% endif %}

  2. {% for account in ([real_account] if real_account.account else real_account.values()) recursive %} {% if account|should_show %} {% set balance = account.balance|cost_or_value %} {% set balance_children = account|balance_children|cost_or_value %} {% for currency in operating_currencies %} {{ balance.get_currency_units(currency).number|format_currency(currency) }} {{ balance_children.get_currency_units(currency).number|format_currency(currency) }} {% endfor %} {% if show_other_column %} {% for pos in balance|sort(attribute='units.currency') if pos.units.currency not in operating_currencies %} {{ pos.units|format_amount }}
    {% endfor %}
    {% for pos in balance_children|sort(attribute='units.currency') if pos.units.currency not in operating_currencies %} {{ pos.units|format_amount }}
    {% endfor %}
    {% endif %}

    {% if account|length %}
      {{ loop(account.values()|sort(attribute='account')) }}
    {% endif %} {% endif %} {% endfor %} {% if totals %} {% set balance = real_account|balance_children|cost_or_value %}
  3. {% for currency in operating_currencies %} {{ balance.get_currency_units(currency).number|format_currency(currency) }} {% endfor %} {% if show_other_column %} {% for pos in balance|sort(attribute='units.currency') if pos.units.currency not in operating_currencies %} {{ pos.units|format_amount }}
    {% endfor %}
    {% endif %}

  4. {% endif %}
{% endmacro %} {% macro render_budget(budget, currency, number=0) %} {% if budget %} {% if currency in budget %} {% set diff = budget[currency] - number %} ({{ diff|format_currency(currency, show_if_zero=True) }}{{ ' '+currency if not number else '' }}) {% else %} {% endif %} {% endif %} {% endmacro %} {% macro account_tree(account_name, interval_balances, dates, accumulate) %}
  1. {% for begin_date, end_date in dates %} {% if accumulate %} {% set time_filter = dates[0][0]|string + ' - ' + end_date|string %} {% else %} {% set time_filter = begin_date|string + ' - ' + end_date|string %} {% endif %} {{ interval_macros.format_date(begin_date) }} {% endfor %}

  2. {% for account in [interval_balances[0]|get_or_create(account_name)] recursive %}

    {% for begin_date, end_date in dates %} {% if accumulate %}{% set begin_date = dates[-1][0] %}{% endif %} {% set budget = ledger.budgets.calculate(account.account, begin_date, end_date) %} {% set budget_children = ledger.budgets.calculate_children(account.account, begin_date, end_date) %} {% set current_account = interval_balances[loop.index0]|get_or_create(account.account) %} {% set balance = current_account.balance|cost_or_value(end_date) %} {% set balance_children = current_account|balance_children|cost_or_value(end_date) %} {% for pos in balance %} {{ render_budget(budget, pos.units.currency, pos.units.number) }} {{ pos.units|format_amount }} {% endfor %} {% if budget %} {% for currency, number in budget.items() if currency not in balance.currencies() %} {{ render_budget(budget, currency) }} {% endfor %} {% endif %} {% for pos in balance_children %} {{ render_budget(budget_children, pos.units.currency, pos.units.number) }} {{ pos.units|format_amount }} {% endfor %} {% if budget_children %} {% for currency, number in budget_children.items() if currency not in balance_children.currencies() %} {{ render_budget(budget_children, currency) }} {% endfor %} {% endif %} {% endfor %}

      {{ loop(account.values()|sort(attribute='account')) }}
    {% endfor %}
  3. {% for begin_date, end_date in dates %} {% set current_account = interval_balances[loop.index0]|get_or_create(account_name) %} {% set balance_children = current_account|balance_children|cost_or_value(end_date) %} {% for pos in balance_children %} {{ pos.units|format_amount }}
    {% endfor %}
    {% endfor %}

{% endmacro %}