From 79305f8a8f09a8fce10bc3a11584d6e4ed451f18 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 23 Mar 2020 17:28:32 +1100 Subject: [PATCH] Tweak account transactions with commodities to remove redundancy, and show amount details on hover --- ledger_pyreport/__init__.py | 4 ++-- .../jinja2/transactions_commodity.html | 24 +++++++++---------- ledger_pyreport/model.py | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ledger_pyreport/__init__.py b/ledger_pyreport/__init__.py index 1077540..5d04126 100644 --- a/ledger_pyreport/__init__.py +++ b/ledger_pyreport/__init__.py @@ -189,8 +189,8 @@ def transactions_commodity(): account = l.get_account(account) transactions = [t for t in l.transactions if t.date <= date and t.date >= pstart and any(p.account == account for p in t.postings)] - opening_balance = accounting.trial_balance(l, pstart, pstart).get_balance(account) - closing_balance = accounting.trial_balance(l, date, pstart).get_balance(account) + opening_balance = accounting.trial_balance(l, pstart, pstart).get_balance(account).clean() + closing_balance = accounting.trial_balance(l, date, pstart).get_balance(account).clean() def matching_posting(transaction, amount): return next((p for p in transaction.postings if p.account == account and p.amount.currency == amount.currency), None) diff --git a/ledger_pyreport/jinja2/transactions_commodity.html b/ledger_pyreport/jinja2/transactions_commodity.html index eb8c5fd..4e6074a 100644 --- a/ledger_pyreport/jinja2/transactions_commodity.html +++ b/ledger_pyreport/jinja2/transactions_commodity.html @@ -31,7 +31,7 @@ Description Amount - + {##} Balance @@ -43,11 +43,11 @@ {% if loop.first %}{{ pstart.strftime('%Y-%m-%d') }}{% endif %} {% if loop.first %}Opening Balance{% endif %} - + {##} - {{ amount|abs|bc }} - {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} + {{ amount|abs|bc }} + {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} {% if amount >= 0 %}Dr{% else %}Cr{% endif %} {% endfor %} @@ -64,13 +64,13 @@ {% if loop.first %}{{ transaction.description }}{% endif %} {% if posting %} {% if posting.amount >= 0 %}Dr{% else %}Cr{% endif %} - {{ posting.amount|abs|bc }} - {% if posting.amount.currency.price %}{{ '{' + posting.amount.currency.price|bc + '}' }}{% endif %} + {{ posting.amount|abs|bc }} + {#{% if posting.amount.currency.price %}{{ '{' + posting.amount.currency.price|bc + '}' }}{% endif %}#} {% else %} - + {% endif %} - {{ amount|abs|bc }} - {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} + {{ amount|abs|bc }} + {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} {% if amount >= 0 %}Dr{% else %}Cr{% endif %} {% endfor %} @@ -81,11 +81,11 @@ {% if loop.first %}{{ date.strftime('%Y-%m-%d') }}{% endif %} {% if loop.first %}Closing Balance{% endif %} - + {##} - {{ amount|abs|bc }} - {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} + {{ amount|abs|bc }} + {% if amount.currency.price %}{{ '{' + amount.currency.price|bc + '}' }}{% endif %} {% if amount >= 0 %}Dr{% else %}Cr{% endif %} {% endfor %} diff --git a/ledger_pyreport/model.py b/ledger_pyreport/model.py index e6aad20..10104cd 100644 --- a/ledger_pyreport/model.py +++ b/ledger_pyreport/model.py @@ -150,10 +150,10 @@ class Amount: if self.currency.is_prefix: amount_str = ('{}{:.2f}' if round else '{}{}').format(self.currency.name, self.amount) else: - amount_str = ('{:.2f} {}' if round else '{:.2f} {}').format(self.amount, self.currency.name) + amount_str = ('{:.2f} {}' if round else '{} {}').format(self.amount, self.currency.name) if self.currency.price: - return '{} {{{}}}'.format(amount_str, self.currency.price) + return '{} {{{}}}'.format(amount_str, self.currency.price.tostr(round)) return amount_str def __repr__(self):