Display zero balances in trial balance if the account has transactions
This commit is contained in:
parent
3fa8f8a829
commit
6b2fbde482
@ -59,7 +59,11 @@ def trial():
|
|||||||
else:
|
else:
|
||||||
total_cr -= balance
|
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:
|
else:
|
||||||
# Get multiple trial balances for comparison
|
# Get multiple trial balances for comparison
|
||||||
dates = [date.replace(year=date.year - i) for i in range(0, compare + 1)]
|
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)
|
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)]
|
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)
|
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[:]:
|
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)
|
accounts.remove(account)
|
||||||
|
|
||||||
return flask.render_template('trial_multiple.html', trial_balances=trial_balances, accounts=accounts, report_commodity=report_commodity, cash=cash)
|
return flask.render_template('trial_multiple.html', trial_balances=trial_balances, accounts=accounts, report_commodity=report_commodity, cash=cash)
|
||||||
|
@ -30,17 +30,15 @@
|
|||||||
<th class="h1">Dr</th>
|
<th class="h1">Dr</th>
|
||||||
<th class="h1">Cr</th>
|
<th class="h1">Cr</th>
|
||||||
</tr>
|
</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 #}
|
{# Display in "cost basis" as we have already accounted for unrealised gains #}
|
||||||
{% set balance = trial_balance.get_balance(account).exchange(report_commodity, True) %}
|
{% 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 %}
|
{% 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>
|
<tr>
|
||||||
<td><a href="{{ trn_url }}">{{ account.name }}</a></td>
|
<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>
|
||||||
<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>
|
</tr>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<td>{{ account.name }}</td>
|
<td>{{ account.name }}</td>
|
||||||
{% for trial_balance in trial_balances %}
|
{% for trial_balance in trial_balances %}
|
||||||
{% set balance = trial_balance.get_balance(account).exchange(report_commodity, True) %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Reference in New Issue
Block a user