Display zero balances in trial balance if the account has transactions

This commit is contained in:
RunasSudo 2020-04-04 20:08:55 +11:00
parent 3fa8f8a829
commit 6b2fbde482
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 18 additions and 12 deletions

View File

@ -59,7 +59,11 @@ def trial():
else:
total_cr -= balance
return flask.render_template('trial.html', date=date, pstart=pstart, trial_balance=trial_balance, accounts=sorted(l.accounts.values(), key=lambda a: a.name), total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity)
# Identify which accounts have transactions
accounts = sorted(l.accounts.values(), key=lambda a: a.name)
trial_balance.trn_accounts = [a for a in accounts if any(p.account == a for t in l.transactions for p in t.postings if t.date >= pstart and t.date <= date)]
return flask.render_template('trial.html', date=date, pstart=pstart, trial_balance=trial_balance, accounts=accounts, total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity)
else:
# Get multiple trial balances for comparison
dates = [date.replace(year=date.year - i) for i in range(0, compare + 1)]
@ -71,10 +75,14 @@ def trial():
l = accounting.ledger_to_cash(l, report_commodity)
trial_balances = [accounting.trial_balance(l.clone(), d, p, report_commodity) for d, p in zip(dates, pstarts)]
# Delete accounts with always zero balances
# Identify which accounts have transactions in which periods
accounts = sorted(l.accounts.values(), key=lambda a: a.name)
for trial_balance in trial_balances:
trial_balance.trn_accounts = [a for a in accounts if any(p.account == a for t in l.transactions for p in t.postings if t.date >= trial_balance.pstart and t.date <= trial_balance.date)]
# Delete accounts with always no transactions
for account in accounts[:]:
if all(t.get_balance(account).exchange(report_commodity, True).near_zero for t in trial_balances):
if not any(account in b.trn_accounts for b in trial_balances):
accounts.remove(account)
return flask.render_template('trial_multiple.html', trial_balances=trial_balances, accounts=accounts, report_commodity=report_commodity, cash=cash)

View File

@ -30,17 +30,15 @@
<th class="h1">Dr</th>
<th class="h1">Cr</th>
</tr>
{% for account in accounts %}
{% for account in accounts if account in trial_balance.trn_accounts %}
{# Display in "cost basis" as we have already accounted for unrealised gains #}
{% set balance = trial_balance.get_balance(account).exchange(report_commodity, True) %}
{% set trn_url = "/transactions?" + {'date_end': trial_balance.date.strftime('%Y-%m-%d'), 'date_beg': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode %}
{% 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>
<td>{% if balance < 0 %}<a href="{{ trn_url }}">{{ -balance|b }}</a>{% endif %}</td>
</tr>
{% endif %}
<tr>
<td><a href="{{ trn_url }}">{{ account.name }}</a></td>
<td>{% if balance >= 0 %}<a href="{{ trn_url }}">{{ balance|b }}</a>{% endif %}</td>
<td>{% if balance < 0 %}<a href="{{ trn_url }}">{{ -balance|b }}</a>{% endif %}</td>
</tr>
{% endfor %}
<tr class="total">
<td></td>

View File

@ -34,7 +34,7 @@
<td>{{ account.name }}</td>
{% for trial_balance in trial_balances %}
{% set balance = trial_balance.get_balance(account).exchange(report_commodity, True) %}
<td>{% if not balance.near_zero %}<a href="/transactions?{{ {'date_end': trial_balance.date.strftime('%Y-%m-%d'), 'date_beg': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ balance|abs|b }} {% if balance >= 0 %}Dr{% else %}Cr{% endif %}</a>{% endif %}</td>
<td>{% if account in trial_balance.trn_accounts %}<a href="/transactions?{{ {'date_end': trial_balance.date.strftime('%Y-%m-%d'), 'date_beg': trial_balance.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ balance|abs|b }} {% if balance >= 0 %}Dr{% else %}Cr{% endif %}</a>{% endif %}</td>
{% endfor %}
</tr>
{% endfor %}