{% import 'macros/_commodity_macros.html' as commodity_macros %} {% set short_type = { 'balance': 'Bal', 'close': 'Close', 'document': 'Doc', 'note': 'Note', 'open': 'Open', } %} {% macro account_link(name) %}{{ name }}{% endmacro %} {% macro render_metadata_indicators(metadata) -%} {% for key, value in metadata %} {{ key[:2] }} {% endfor %} {%- endmacro %} {% macro render_metadata(metadata, entry_hash=None) -%} {% if metadata %}
{% for key, value in metadata %}
{{ key }}:
{%- if key.startswith('document') %}{{ value }} {% elif value is string and (value.startswith('http://') or value.startswith('https://')) %}{{ value }} {% else %} {{ value }} {% endif -%}
{% endfor %}
{% endif %} {% endmacro %} {% macro render_tags_links(entry) -%} {% for tag in entry.tags|sort %}#{{ tag }}{% endfor %} {% for link_ in entry.links|sort %}^{{ link_ }}{% endfor %} {%- endmacro %} {% macro journal_table(entries, show_change_and_balance=False, ledger=None) %} {% set ledger = ledger or g.ledger %} {% autoescape false %}
  1. {{ _('Date') }} {{ _('F') }} {{ _('Payee') }}/{{ _('Narration') }} {{ _('Units') }} {{ _('Cost') }}{% if show_change_and_balance %} / {{ _('Change') }}{% endif %} {{ _('Price') }}{% if show_change_and_balance %} / {{ _('Balance') }}{% endif %}

  2. {% for entry in entries %} {% if show_change_and_balance %} {% set entry, change, balance = entry %} {% endif %} {% set type = entry.__class__.__name__.lower() %} {% set metadata_items = entry.meta|meta_items %} {% if type == 'price' %}{% continue %}{% endif %} {% set entry_hash = entry|hash_entry %}
  3. {{ entry.date }} {% if type == 'transaction' %}{{ entry.flag }}{% else %}{{ short_type.get(type, type[:3]) }}{% endif %} {% if type == 'open' or type == 'close' %} {{ account_link(entry.account) }} {% elif type == 'note' %} {{ entry.comment }} {% elif type == 'query' %} {{ entry.name }} {% elif type == 'pad' %} {{ account_link(entry.account) }} from {{ account_link(entry.source_account) }} {% elif type == 'custom' %} {{ entry.type }} {%- for value in entry['values'] -%}  {% if value.dtype|string == "" %}{{ account_link(value.value) }} {%- elif value.dtype|string == "" %}{{ commodity_macros.render_amount(ledger, value.value) }} {%- elif value.dtype|string == "" %}"{{ value.value }}" {%- elif value.dtype|string == "" %}{{ value.value }} {%- elif value.dtype|string == "" %}{{ value.value }}{% endif -%} {%- endfor -%} {% elif type == 'document' %} {{ account_link(entry.account) }} {{ entry.filename|basename }} {{ render_tags_links(entry) }} {% elif type == 'balance' %} {{ account_link(entry.account) }} {% if entry.diff_amount %} accumulated {{ (entry.amount.number + entry.diff_amount.number)|format_currency(entry.amount.currency, show_if_zero=True) }} {{ entry.amount.currency }} {% endif %} {% elif type == 'transaction' %} {{ entry.payee or '' }}{% if entry.payee and entry.narration %}{% endif %}{{ entry.narration or '' }} {{ render_tags_links(entry) }} {% endif %} {{ render_metadata_indicators(metadata_items) }} {% for posting in entry.postings %} {{ render_metadata_indicators(posting.meta|meta_items) }} {% endfor %} {% if type == 'balance' %} {{ commodity_macros.render_amount(ledger, entry.amount, 'num bal' + (' pending' if entry.diff_amount else '')) }} {% if entry.diff_amount %} {{ commodity_macros.render_num(ledger, entry.diff_amount.currency, entry.diff_amount.number) }} {% else %} {% endif %} {% if not show_change_and_balance %} {% endif %} {% endif %} {% if show_change_and_balance %} {% if type == 'transaction' %} {%- for currency, number in change.items() %}{{ commodity_macros.render_num(ledger, currency, number) }}
    {% endfor -%}
    {% endif %} {%- for currency, number in balance.items() %}{{ commodity_macros.render_num(ledger, currency, number) }}
    {% endfor -%}
    {% endif %}

    {{ render_metadata(metadata_items, entry_hash) }} {% if entry.postings %}
      {% for posting in entry.postings %}

      {{ posting.flag or '' }} {{ account_link(posting.account) }} {# We want the output these amounts with the same precision as in the input file. For computed values this might give a lot of digits, so format the price using the DisplayContext for now.#} {% if posting.units %}{{ posting.units.number|incognito }} {{ posting.units.currency }}{% endif %} {{ posting.cost.number|incognito }} {{ posting.cost.currency }} {{- ', {}'.format(posting.cost.date) if posting.cost.date else '' }} {{- ', "{}"'.format(posting.cost.label) if posting.cost.label else '' }} {{ commodity_macros.render_amount(ledger, posting.price) }}

      {{ render_metadata(posting.meta|meta_items) }} {% endfor %}
    {% endif %}
  4. {% endfor %}
{% endautoescape %} {%- endmacro %}