Improve display of chart of accounts

Group account kinds by plugin
Display label instead of ID
This commit is contained in:
RunasSudo 2023-01-07 01:09:17 +11:00
parent d7289bd2d0
commit 66b3ddff54
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 28 additions and 10 deletions

View File

@ -19,7 +19,14 @@ from .webapp import app
import importlib
advanced_reports = [] # list of tuplet (url, label)
account_kinds = [] # list of tuplet (id, label)
account_kinds = [
# list of tuplet (id, label)
('drcr.asset', 'Asset'),
('drcr.liability', 'Liability'),
('drcr.income', 'Income'),
('drcr.expense', 'Expense'),
('drcr.equity', 'Equity')
]
transaction_providers = [] # list of callable
def init_plugins():

View File

@ -25,14 +25,13 @@
<div class="d-flex py-2 bg-white sticky-top">
<div class="me-2">
<select class="form-select" name="kind">
<option value="drcr.asset">Asset</option>
<option value="drcr.liability">Liability</option>
<option value="drcr.income">Income</option>
<option value="drcr.expense">Expense</option>
<option value="drcr.equity">Equity</option>
{% for account_kind in account_kinds %}
{% for plugin_name, plugin_account_kinds in account_kinds_by_plugin.items() %}
<optgroup label="{{ plugin_name }}">
{% for account_kind in plugin_account_kinds %}
<option value="{{ account_kind[0] }}">{{ account_kind[1] }}</option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
</div>
<div>
@ -57,7 +56,7 @@
{% if account in account_configurations %}
<ul class="mb-0">
{% for account_configuration in account_configurations[account] %}
<li>{{ account_configuration.kind }}</li>
<li>{{ account_kinds_map[account_configuration.kind] }}</li>
{% endfor %}
</ul>
{% endif %}

View File

@ -22,6 +22,8 @@ from .plugins import account_kinds, advanced_reports
from .reports import balance_sheet_report, income_statement_report
from .webapp import all_transactions, app
from itertools import groupby
@app.route('/')
def index():
return render_template('index.html', advanced_reports=advanced_reports)
@ -34,8 +36,18 @@ def chart_of_accounts():
# Get existing AccountConfiguration's
account_configurations = AccountConfiguration.get_all()
# Preprocess account kinds
account_kinds_by_plugin = {v: list(g) for v, g in groupby(account_kinds, key=lambda k: k[0][:k[0].index('.')])}
account_kinds_map = {name: label for name, label in account_kinds}
# TODO: Handle orphans
return render_template('chart_of_accounts.html', accounts=accounts, account_configurations=account_configurations, account_kinds=account_kinds)
return render_template(
'chart_of_accounts.html',
accounts=accounts,
account_configurations=account_configurations,
account_kinds_by_plugin=account_kinds_by_plugin,
account_kinds_map=account_kinds_map
)
@app.route('/chart-of-accounts/add-kind', methods=['POST'])
def account_add_kind():