Hide accounts with nonzero balances that round to zero
This commit is contained in:
parent
bbd99af710
commit
742b613534
@ -99,7 +99,7 @@ def balance():
|
||||
# Delete accounts with always zero balances
|
||||
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):
|
||||
if all(b.get_balance(account).exchange(report_currency, True).near_zero and b.get_total(account).exchange(report_currency, True).near_zero for b in balance_sheets):
|
||||
accounts.remove(account)
|
||||
|
||||
return flask.render_template('balance.html', ledger=l, balance_sheets=balance_sheets, accounts=accounts, config=config, report_currency=report_currency, cash=cash)
|
||||
@ -173,7 +173,7 @@ def transactions():
|
||||
|
||||
@app.template_filter('a')
|
||||
def filter_amount(amt):
|
||||
if amt.amount < 0.005 and amt.amount >= -0.005:
|
||||
if amt.near_zero:
|
||||
return flask.Markup('0.00 ')
|
||||
elif amt > 0:
|
||||
return flask.Markup('{:,.2f} '.format(amt.amount).replace(',', ' ')) # Narrow no-break space
|
||||
@ -220,7 +220,7 @@ def debug_imbalances():
|
||||
if cash:
|
||||
l = accounting.ledger_to_cash(l, report_currency)
|
||||
|
||||
transactions = [t for t in l.transactions if t.date <= date and t.date >= pstart and abs(sum((p.amount for p in t.postings), Balance()).exchange(report_currency, True).amount) > 0.005]
|
||||
transactions = [t for t in l.transactions if t.date <= date and t.date >= pstart and not sum((p.amount for p in t.postings), Balance()).exchange(report_currency, True).near_zero]
|
||||
|
||||
total_dr = sum((p.amount for t in transactions for p in t.postings if p.amount > 0), Balance()).exchange(report_currency, True)
|
||||
total_cr = sum((p.amount for t in transactions for p in t.postings if p.amount < 0), Balance()).exchange(report_currency, True)
|
||||
|
@ -36,7 +36,7 @@
|
||||
{% for balance_sheet in balance_sheets %}
|
||||
{% set amount = (-balance_sheet.get_balance(account) if invert else balance_sheet.get_balance(account)).exchange(report_currency, True) %}
|
||||
<td>
|
||||
{% if amount != 0 %}
|
||||
{% if not amount.near_zero %}
|
||||
{% if account.name == config['current_year_earnings'] %}
|
||||
<a href="/pandl?{{ {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0', 'cash': 'on' if cash else ''}|urlencode }}">
|
||||
{% else %}
|
||||
|
@ -29,7 +29,7 @@
|
||||
</td>
|
||||
{% for pandl in pandls %}
|
||||
{% set amount = (-pandl.get_balance(account) if invert else pandl.get_balance(account)).exchange(report_currency, True) %}
|
||||
<td>{% if amount != 0 %}<a href="/transactions?{{ {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ amount|a }}</a>{% endif %}</td>
|
||||
<td>{% if not amount.near_zero %}<a href="/transactions?{{ {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ amount|a }}</a>{% endif %}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
{# Display in "cost basis" as we have already accounted for unrealised gains #}
|
||||
{% set balance = trial_balance.get_balance(account).exchange(report_currency, True) %}
|
||||
{% set trn_url = "/transactions?" + {'date': trial_balance.date.strftime('%Y-%m-%d'), 'pstart': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode %}
|
||||
{% if balance != 0 %}
|
||||
{% if not balance.near_zero %}
|
||||
<tr>
|
||||
<td><a href="{{ trn_url }}">{{ account.name }}</a></td>
|
||||
<td>{% if balance > 0 %}<a href="{{ trn_url }}">{{ balance|b }}</a>{% endif %}</td>
|
||||
|
@ -34,7 +34,7 @@
|
||||
<td>{{ account.name }}</td>
|
||||
{% for trial_balance in trial_balances %}
|
||||
{% set balance = trial_balance.get_balance(account).exchange(report_currency, True) %}
|
||||
<td>{% if balance != 0 %}<a href="/transactions?{{ {'date': trial_balance.date.strftime('%Y-%m-%d'), 'pstart': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ balance|a }}</a>{% endif %}</td>
|
||||
<td>{% if not balance.near_zero %}<a href="/transactions?{{ {'date': trial_balance.date.strftime('%Y-%m-%d'), 'pstart': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ balance|a }}</a>{% endif %}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -221,6 +221,12 @@ class Amount:
|
||||
|
||||
raise TypeError('Cannot exchange {} to {}'.format(self.currency, currency))
|
||||
|
||||
@property
|
||||
def near_zero(self):
|
||||
if abs(self.amount) < 0.005:
|
||||
return True
|
||||
return False
|
||||
|
||||
class Balance:
|
||||
def __init__(self, amounts=None):
|
||||
self.amounts = amounts or []
|
||||
|
Reference in New Issue
Block a user