Use url_for for internal links

This commit is contained in:
RunasSudo 2023-01-07 19:01:05 +11:00
parent 46b041d9dc
commit 08ff000899
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
19 changed files with 67 additions and 65 deletions

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import render_template from flask import render_template, url_for
from drcr.models import AccountConfiguration, Posting, Transaction, TrialBalancer from drcr.models import AccountConfiguration, Posting, Transaction, TrialBalancer
from drcr.database import db from drcr.database import db
@ -24,9 +24,9 @@ from .reports import eofy_date, tax_summary_report
from . import views from . import views
def plugin_init(): def plugin_init():
drcr.plugins.data_sources.append(('/tax/cgt-adjustments', 'CGT adjustments')) drcr.plugins.data_sources.append(('cgt_adjustments', 'CGT adjustments'))
drcr.plugins.advanced_reports.append(('/tax/cgt-assets', 'CGT assets')) drcr.plugins.advanced_reports.append(('cgt_assets', 'CGT assets'))
drcr.plugins.advanced_reports.append(('/tax/summary', 'Tax summary')) drcr.plugins.advanced_reports.append(('tax_summary', 'Tax summary'))
drcr.plugins.account_kinds.append(('austax.income1', 'Salary or wages (1)')) drcr.plugins.account_kinds.append(('austax.income1', 'Salary or wages (1)'))
drcr.plugins.account_kinds.append(('austax.income5', 'Australian Government allowances and payments (5)')) drcr.plugins.account_kinds.append(('austax.income5', 'Australian Government allowances and payments (5)'))

View File

@ -22,8 +22,8 @@
<h1 class="h2 my-4">CGT adjustments</h1> <h1 class="h2 my-4">CGT adjustments</h1>
<div class="mb-2"> <div class="mb-2">
<a href="/tax/cgt-adjustments/new" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New CGT adjustment</a> <a href="{{ url_for('cgt_adjustment_new') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New CGT adjustment</a>
<a href="/tax/cgt-adjustments/multi-new" class="btn btn-outline-primary"><i class="bi bi-plus-lg"></i> Multiple CGT adjustments</a> <a href="{{ url_for('cgt_adjustment_multinew') }}" class="btn btn-outline-primary"><i class="bi bi-plus-lg"></i> Multiple CGT adjustments</a>
</div> </div>
<table class="table"> <table class="table">
@ -51,7 +51,7 @@
<td>{{ cgt_adjustment.dt.strftime('%Y-%m-%d') }}</td> <td>{{ cgt_adjustment.dt.strftime('%Y-%m-%d') }}</td>
<td>{{ cgt_adjustment.description }}</td> <td>{{ cgt_adjustment.description }}</td>
<td class="text-end">{{ cgt_adjustment.cost_adjustment_amount().format_accounting() }}</td> <td class="text-end">{{ cgt_adjustment.cost_adjustment_amount().format_accounting() }}</td>
<td><a href="/tax/cgt-adjustments/edit?id={{ cgt_adjustment.id }}"><i class="bi bi-pencil"></i></a></td> <td><a href="{{ url_for('cgt_adjustment_edit', id=cgt_adjustment.id) }}"><i class="bi bi-pencil"></i></a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -50,14 +50,14 @@
<tbody> <tbody>
{% for asset in assets %} {% for asset in assets %}
<tr> <tr>
<td><a href="/account-transactions?account={{ asset.account }}&commodity-detail=1">{{ asset.account }}</a></td> <td><a href="{{ url_for('account_transactions', account=asset.account, commodity_detail=1) }}">{{ asset.account }}</a></td>
<td>{{ asset.commodity_name() }}</td> <td>{{ asset.commodity_name() }}</td>
<td class="text-end">{{ asset.format('hide') }}</td> <td class="text-end">{{ asset.format('hide') }}</td>
<td style="border-left-width:1px">{{ asset.acquisition_date.strftime('%Y-%m-%d') }}</td> <td style="border-left-width:1px">{{ asset.acquisition_date.strftime('%Y-%m-%d') }}</td>
<td class="text-end">{{ asset.as_cost().format() }}</td> <td class="text-end">{{ asset.as_cost().format() }}</td>
<td style="border-left-width:1px" class="text-end">{{ asset.cost_adjustment().format_accounting(link="/tax/cgt-adjustments?account={}&commodity={}&quantity={}&acquisition_date={:%Y-%m-%d}".format(asset.account, asset.commodity, asset.quantity, asset.acquisition_date)) if asset.cost_adjustments }}</td> <td style="border-left-width:1px" class="text-end">{{ asset.cost_adjustment().format_accounting(link=url_for('cgt_adjustments', account=asset.account, commodity=asset.commodity, quantity=asset.quantity, acquisition_date=asset.acquisition_date.strftime('%Y-%m-%d'))) if asset.cost_adjustments }}</td>
<td>{# TODO #}</td> <td>{# TODO #}</td>
<td class="text-center d-print-none"><a href="/tax/cgt-adjustments/new?account={{ asset.account }}&asset={{ asset.quantity_string() }}&acquisition_date={{ asset.acquisition_date.strftime('%Y-%m-%d') }}"><i class="bi bi-plus-lg text-muted"></i></a></td> <td class="text-center d-print-none"><a href="{{ url_for('cgt_adjustment_new', account=asset.account, asset=asset.quantity_string(), acquisition_date=asset.acquisition_date.strftime('%Y-%m-%d')) }}"><i class="bi bi-plus-lg text-muted"></i></a></td>
<td style="border-left-width:1px">{{ asset.disposal_date.strftime('%Y-%m-%d') if asset.disposal_date else '' }}</td> <td style="border-left-width:1px">{{ asset.disposal_date.strftime('%Y-%m-%d') if asset.disposal_date else '' }}</td>
<td class="text-end">{{ asset.disposal_value.format() if asset.disposal_value else '' }}</td> <td class="text-end">{{ asset.disposal_value.format() if asset.disposal_value else '' }}</td>
<td style="border-left-width:1px" class="text-end">{% if asset.disposal_date %}{{ asset.gain().format_accounting() }}{% endif %}</td> <td style="border-left-width:1px" class="text-end">{% if asset.disposal_date %}{{ asset.gain().format_accounting() }}{% endif %}</td>

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import redirect, render_template, request from flask import redirect, render_template, request, url_for
from drcr.models import AccountConfiguration, Amount, Posting, Transaction from drcr.models import AccountConfiguration, Amount, Posting, Transaction
from drcr.database import db from drcr.database import db
@ -60,7 +60,7 @@ def cgt_adjustment_new():
db.session.add(adjustment) db.session.add(adjustment)
db.session.commit() db.session.commit()
return redirect('/tax/cgt-adjustments') return redirect(url_for('cgt_adjustments'))
@app.route('/tax/cgt-adjustments/edit', methods=['GET', 'POST']) @app.route('/tax/cgt-adjustments/edit', methods=['GET', 'POST'])
def cgt_adjustment_edit(): def cgt_adjustment_edit():
@ -80,7 +80,7 @@ def cgt_adjustment_edit():
db.session.add(adjustment) db.session.add(adjustment)
db.session.commit() db.session.commit()
return redirect('/tax/cgt-adjustments') return redirect(url_for('cgt_adjustments'))
@app.route('/tax/cgt-adjustments/multi-new', methods=['GET', 'POST']) @app.route('/tax/cgt-adjustments/multi-new', methods=['GET', 'POST'])
def cgt_adjustment_multinew(): def cgt_adjustment_multinew():
@ -166,7 +166,7 @@ def cgt_adjustment_multinew():
db.session.commit() db.session.commit()
return redirect('/tax/cgt-adjustments') return redirect(url_for('cgt_adjustments'))
@app.route('/tax/cgt-assets') @app.route('/tax/cgt-assets')
def cgt_assets(): def cgt_assets():

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import abort, redirect, render_template, request from flask import abort, redirect, render_template, request, url_for
from .. import AMOUNT_DPS from .. import AMOUNT_DPS
from ..database import db from ..database import db
@ -31,7 +31,7 @@ def journal():
return render_template( return render_template(
'journal/journal.html', 'journal/journal.html',
commodity_detail=request.args.get('commodity-detail', '0') == '1', commodity_detail=request.args.get('commodity_detail', '0') == '1',
transactions=transactions transactions=transactions
) )
@ -64,7 +64,7 @@ def journal_new_transaction():
db.session.add(transaction) db.session.add(transaction)
db.session.commit() db.session.commit()
return redirect('/journal') return redirect(url_for('journal'))
@app.route('/journal/edit-transaction', methods=['GET', 'POST']) @app.route('/journal/edit-transaction', methods=['GET', 'POST'])
def journal_edit_transaction(): def journal_edit_transaction():
@ -109,7 +109,7 @@ def journal_edit_transaction():
db.session.commit() db.session.commit()
return redirect('/journal') return redirect(url_for('journal'))
@app.route('/balance-assertions') @app.route('/balance-assertions')
def balance_assertions(): def balance_assertions():
@ -151,7 +151,7 @@ def balance_assertions_new():
db.session.add(assertion) db.session.add(assertion)
db.session.commit() db.session.commit()
return redirect('/balance-assertions') return redirect(url_for('balance_assertions'))
@app.route('/balance-assertions/edit', methods=['GET', 'POST']) @app.route('/balance-assertions/edit', methods=['GET', 'POST'])
def balance_assertions_edit(): def balance_assertions_edit():
@ -174,4 +174,4 @@ def balance_assertions_edit():
db.session.commit() db.session.commit()
return redirect('/balance-assertions') return redirect(url_for('balance_assertions'))

View File

@ -21,8 +21,8 @@ from .webapp import app
import importlib import importlib
data_sources = [] # list of tuplet (url, label) data_sources = [] # list of tuplet (view name, label)
advanced_reports = [] # list of tuplet (url, label) advanced_reports = [] # list of tuplet (view name, label)
account_kinds = [ account_kinds = [
# list of tuplet (id, label) # list of tuplet (id, label)

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import url_for
from .models import AccountConfiguration, Amount, TrialBalancer from .models import AccountConfiguration, Amount, TrialBalancer
from .webapp import all_transactions from .webapp import all_transactions
@ -123,7 +125,7 @@ def entries_for_kind(account_configurations, accounts, kind, neg=False, floor=0)
amount = -amount amount = -amount
if floor: if floor:
amount.quantity = (amount.quantity // floor) * floor amount.quantity = (amount.quantity // floor) * floor
entries.append(Entry(text=account_name, amount=amount, link='/account-transactions?account=' + account_name)) entries.append(Entry(text=account_name, amount=amount, link=url_for('account_transactions', account=account_name)))
return entries return entries
def balance_sheet_report(): def balance_sheet_report():
@ -156,7 +158,7 @@ def balance_sheet_report():
Calculated( Calculated(
'Current year surplus (deficit)', 'Current year surplus (deficit)',
lambda _: income_statement_report().by_id('net_surplus').amount, lambda _: income_statement_report().by_id('net_surplus').amount,
link='/income-statement' link=url_for('income_statement')
), ),
Subtotal('Total equity', bordered=True) Subtotal('Total equity', bordered=True)
] ]

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import abort, redirect, render_template, request from flask import abort, redirect, render_template, request, url_for
from .. import AMOUNT_DPS from .. import AMOUNT_DPS
from ..database import db from ..database import db
@ -94,7 +94,7 @@ def statement_line_reconcile_transfer():
db.session.add(transaction) db.session.add(transaction)
db.session.commit() db.session.commit()
return redirect('/statement-lines') return redirect(url_for('statement_lines'))
@app.route('/statement-lines/import', methods=['GET', 'POST']) @app.route('/statement-lines/import', methods=['GET', 'POST'])
def statement_lines_import(): def statement_lines_import():
@ -123,4 +123,4 @@ def statement_lines_import():
db.session.add(statement_line) db.session.add(statement_line)
db.session.commit() db.session.commit()
return redirect('/statement-lines') return redirect(url_for('statement_lines'))

View File

@ -35,12 +35,12 @@
{% block body %} {% block body %}
<nav class="navbar navbar-expand-sm navbar-light bg-light d-print-none"> <nav class="navbar navbar-expand-sm navbar-light bg-light d-print-none">
<div class="container"> <div class="container">
<a class="navbar-brand" href="/">DrCr</a> <a class="navbar-brand" href="{{ url_for('index') }}">DrCr</a>
<div class="collapse navbar-collapse"> <div class="collapse navbar-collapse">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="/journal">Journal</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('journal') }}">Journal</a></li>
<li class="nav-item"><a class="nav-link" href="/statement-lines">Statement lines</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('statement_lines') }}">Statement lines</a></li>
<li class="nav-item"><a class="nav-link" href="/trial-balance">Trial balance</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('trial_balance') }}">Trial balance</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -35,7 +35,7 @@
</select> </select>
</div> </div>
<div> <div>
<button type="submit" class="btn btn-primary" formaction="/chart-of-accounts/add-kind">Add kind</button> <button type="submit" class="btn btn-primary" formaction="{{ url_for('account_add_kind') }}">Add kind</button>
</div> </div>
</div> </div>

View File

@ -23,9 +23,9 @@
<div class="mb-2"> <div class="mb-2">
{% if commodity_detail %} {% if commodity_detail %}
<a href="?commodity-detail=0" class="btn btn-outline-secondary">Hide commodity detail</a> <a href="{{ url_for('general_ledger') }}" class="btn btn-outline-secondary">Hide commodity detail</a>
{% else %} {% else %}
<a href="?commodity-detail=1" class="btn btn-outline-secondary">Show commodity detail</a> <a href="{{ url_for('general_ledger', commodity_detail=1) }}" class="btn btn-outline-secondary">Show commodity detail</a>
{% endif %} {% endif %}
</div> </div>

View File

@ -21,27 +21,27 @@
{% block content %} {% block content %}
<h1 class="h2 my-4">Data sources</h1> <h1 class="h2 my-4">Data sources</h1>
<ul> <ul>
<li><a href="/journal">Journal</a></li> <li><a href="{{ url_for('journal') }}">Journal</a></li>
<li><a href="/statement-lines">Statement lines</a></li> <li><a href="{{ url_for('statement_lines') }}">Statement lines</a></li>
<li><a href="/balance-assertions">Balance assertions</a></li> <li><a href="{{ url_for('balance_assertions') }}">Balance assertions</a></li>
<li><a href="/chart-of-accounts">Chart of accounts</a></li> <li><a href="{{ url_for('chart_of_accounts') }}">Chart of accounts</a></li>
{% for report in data_sources %} {% for report in data_sources %}
<li><a href="{{ report[0] }}">{{ report[1] }}</a></li> <li><a href="{{ url_for(report[0]) }}">{{ report[1] }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
<h1 class="h2 my-4">General reports</h1> <h1 class="h2 my-4">General reports</h1>
<ul> <ul>
<li><a href="/general-ledger">General ledger</a></li> <li><a href="{{ url_for('general_ledger') }}">General ledger</a></li>
<li><a href="/trial-balance">Trial balance</a></li> <li><a href="{{ url_for('trial_balance') }}">Trial balance</a></li>
<li><a href="/balance-sheet">Balance sheet</a></li> <li><a href="{{ url_for('balance_sheet') }}">Balance sheet</a></li>
<li><a href="/income-statement">Income statement</a></li> <li><a href="{{ url_for('income_statement') }}">Income statement</a></li>
</ul> </ul>
<h1 class="h2 my-4">Advanced reports</h1> <h1 class="h2 my-4">Advanced reports</h1>
<ul> <ul>
{% for report in advanced_reports %} {% for report in advanced_reports %}
<li><a href="{{ report[0] }}">{{ report[1] }}</a></li> <li><a href="{{ url_for(report[0]) }}">{{ report[1] }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -22,7 +22,7 @@
<h1 class="h2 my-4">Balance assertions</h1> <h1 class="h2 my-4">Balance assertions</h1>
<div class="mb-2"> <div class="mb-2">
<a href="/balance-assertions/new" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New assertion</a> <a href="{{ url_for('balance_assertions_new') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New assertion</a>
</div> </div>
<table class="table"> <table class="table">
@ -46,7 +46,7 @@
<td class="text-end">{{ (assertion.balance()|abs).format() }}</td> <td class="text-end">{{ (assertion.balance()|abs).format() }}</td>
<td>{{ 'Dr' if assertion.quantity >= 0 else 'Cr' }}</td> <td>{{ 'Dr' if assertion.quantity >= 0 else 'Cr' }}</td>
<td>{% if assertion_status[assertion] %}<i class="bi bi-check-lg"></i>{% else %}<i class="bi bi-x-circle-fill text-danger"></i>{% endif %}</td> <td>{% if assertion_status[assertion] %}<i class="bi bi-check-lg"></i>{% else %}<i class="bi bi-x-circle-fill text-danger"></i>{% endif %}</td>
<td><a href="/balance-assertions/edit?id={{ assertion.id }}"><i class="bi bi-pencil"></i></a></td> <td><a href="{{ url_for('balance_assertions_edit', id=assertion.id) }}"><i class="bi bi-pencil"></i></a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -22,11 +22,11 @@
<h1 class="h2 my-4">Journal</h1> <h1 class="h2 my-4">Journal</h1>
<div class="mb-2"> <div class="mb-2">
<a href="/journal/new-transaction" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New transaction</a> <a href="{{ url_for('journal_new_transaction') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New transaction</a>
{% if commodity_detail %} {% if commodity_detail %}
<a href="?commodity-detail=0" class="btn btn-outline-secondary">Hide commodity detail</a> <a href="{{ url_for('journal') }}" class="btn btn-outline-secondary">Hide commodity detail</a>
{% else %} {% else %}
<a href="?commodity-detail=1" class="btn btn-outline-secondary">Show commodity detail</a> <a href="{{ url_for('journal', commodity_detail=1) }}" class="btn btn-outline-secondary">Show commodity detail</a>
{% endif %} {% endif %}
</div> </div>
@ -43,7 +43,7 @@
{% for transaction in transactions %} {% for transaction in transactions %}
<tr> <tr>
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td> <td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
<td colspan="3">{{ transaction.description }} <a href="/journal/edit-transaction?id={{ transaction.id }}"><i class="bi bi-pencil text-muted"></i></a></td> <td colspan="3">{{ transaction.description }} <a href="{{ url_for('journal_edit_transaction', id=transaction.id) }}"><i class="bi bi-pencil text-muted"></i></a></td>
<td></td> <td></td>
<td></td> <td></td>
</tr> </tr>

View File

@ -25,7 +25,7 @@
<div class="mb-2 d-flex"> <div class="mb-2 d-flex">
{#<button type="submit" class="btn btn-outline-secondary" formaction="/statement-lines/reconcile-transfer">Reconcile selected as transfer</button>#} {#<button type="submit" class="btn btn-outline-secondary" formaction="/statement-lines/reconcile-transfer">Reconcile selected as transfer</button>#}
<div class="flex-grow-1"> <div class="flex-grow-1">
<a href="/statement-lines/import" class="btn btn-outline-secondary">Import statement</a> <a href="{{ url_for('statement_lines_import') }}" class="btn btn-outline-secondary">Import statement</a>
</div> </div>
<nav class="flex-end"> <nav class="flex-end">
<ul class="pagination"> <ul class="pagination">
@ -68,12 +68,12 @@
{# TODO #} {# TODO #}
{% elif line.is_complex() %} {% elif line.is_complex() %}
<i>(Complex)</i> <i>(Complex)</i>
<a href="/journal/edit-transaction?id={{ line.reconciliation.posting.transaction.id }}" class="text-muted"><i class="bi bi-pencil"></i></a> <a href="{{ url_for('journal_edit_transaction', id=line.reconciliation.posting.transaction.id) }}" class="text-muted"><i class="bi bi-pencil"></i></a>
{% else %} {% else %}
{% for posting in line.reconciliation.posting.transaction.postings if posting.account != line.source_account %} {% for posting in line.reconciliation.posting.transaction.postings if posting.account != line.source_account %}
<a href="#" class="text-body" onclick="classifyLine({{ line.id }});return false;">{{ posting.account }}</a> <a href="#" class="text-body" onclick="classifyLine({{ line.id }});return false;">{{ posting.account }}</a>
{% endfor %} {% endfor %}
<a href="/journal/edit-transaction?id={{ line.reconciliation.posting.transaction.id }}" class="text-muted"><i class="bi bi-pencil"></i></a> <a href="{{ url_for('journal_edit_transaction', id=line.reconciliation.posting.transaction.id) }}" class="text-muted"><i class="bi bi-pencil"></i></a>
{% endif %} {% endif %}
</td> </td>
<td class="text-end">{{ line.amount().format() if line.quantity >= 0 else '' }}</td> <td class="text-end">{{ line.amount().format() if line.quantity >= 0 else '' }}</td>
@ -103,7 +103,7 @@
alert('Error when charging statement line'); alert('Error when charging statement line');
} }
}); });
xhr.open('POST', '/statement-lines/charge'); xhr.open('POST', '{{ url_for("statement_line_charge") }}');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('line-id=' + lineId + '&charge-account=' + chargeAccount); xhr.send('line-id=' + lineId + '&charge-account=' + chargeAccount);
} }

View File

@ -22,8 +22,8 @@
<h1 class="h2 my-4">Account transactions</h1> <h1 class="h2 my-4">Account transactions</h1>
<div class="mb-2"> <div class="mb-2">
<a href="/journal/new-transaction" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New transaction</a> <a href="{{ url_for('journal_new_transaction') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New transaction</a>
<a href="?account={{ account }}&commodity-detail=1" class="btn btn-outline-secondary">Show commodity detail</a> <a href="{{ url_for('account_transactions', account=account, commodity_detail=1) }}" class="btn btn-outline-secondary">Show commodity detail</a>
</div> </div>
<table class="table"> <table class="table">
@ -47,7 +47,7 @@
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td> <td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
<td> <td>
{{ transaction.description }} {{ transaction.description }}
{% if transaction.id %}<a href="/journal/edit-transaction?id={{ transaction.id }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %} {% if transaction.id %}<a href="{{ url_for('journal_edit_transaction', id=transaction.id) }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %}
</td> </td>
<td>{% for p in transaction.postings if p.account != account %}{{ p.account }}{% endfor %}</td> <td>{% for p in transaction.postings if p.account != account %}{{ p.account }}{% endfor %}</td>
<td class="text-end">{{ posting.amount().as_cost().format() if posting.quantity >= 0 else '' }}</td> <td class="text-end">{{ posting.amount().as_cost().format() if posting.quantity >= 0 else '' }}</td>
@ -61,7 +61,7 @@
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td> <td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
<td colspan="2"> <td colspan="2">
{{ transaction.description }} {{ transaction.description }}
{% if transaction.id %}<a href="/journal/edit-transaction?id={{ transaction.id }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %} {% if transaction.id %}<a href="{{ url_for('journal_edit_transaction', id=transaction.id) }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %}
</td> </td>
<td></td> <td></td>
<td></td> <td></td>

View File

@ -22,7 +22,7 @@
<h1 class="h2 my-4">Account transactions</h1> <h1 class="h2 my-4">Account transactions</h1>
<div class="mb-2"> <div class="mb-2">
<a href="?account={{ account }}&commodity-detail=0" class="btn btn-outline-secondary">Hide commodity detail</a> <a href="{{ url_for('account_transactions', account=account) }}" class="btn btn-outline-secondary">Hide commodity detail</a>
</div> </div>
<table class="table table-sm table-borderless"> <table class="table table-sm table-borderless">
@ -42,7 +42,7 @@
<td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td> <td>{{ transaction.dt.strftime('%Y-%m-%d') }}</td>
<td> <td>
{{ transaction.description }} {{ transaction.description }}
{% if transaction.id %}<a href="/journal/edit-transaction?id={{ transaction.id }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %} {% if transaction.id %}<a href="{{ url_for('journal_edit_transaction', id=transaction.id) }}"><i class="bi bi-pencil text-muted"></i></a>{% endif %}
</td> </td>
<td></td> <td></td>
<td></td> <td></td>

View File

@ -32,7 +32,7 @@
<tbody> <tbody>
{% for name, balance in accounts.items() %} {% for name, balance in accounts.items() %}
<tr> <tr>
<td><a href="/account-transactions?account={{ name }}">{{ name }}</a></td> <td><a href="{{ url_for('account_transactions', account=name) }}">{{ name }}</a></td>
<td class="text-end">{{ balance.format() if balance.quantity >= 0 else '' }}</td> <td class="text-end">{{ balance.format() if balance.quantity >= 0 else '' }}</td>
<td class="text-end">{{ (balance|abs).format() if balance.quantity < 0 else '' }}</td> <td class="text-end">{{ (balance|abs).format() if balance.quantity < 0 else '' }}</td>
</tr> </tr>

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import redirect, render_template, request from flask import redirect, render_template, request, url_for
from .database import db from .database import db
from .models import AccountConfiguration, Amount, Balance, Posting, TrialBalancer from .models import AccountConfiguration, Amount, Balance, Posting, TrialBalancer
@ -57,13 +57,13 @@ def account_add_kind():
db.session.commit() db.session.commit()
return redirect('/chart-of-accounts') return redirect(url_for('chart_of_accounts'))
@app.route('/general-ledger') @app.route('/general-ledger')
def general_ledger(): def general_ledger():
return render_template( return render_template(
'general_ledger.html', 'general_ledger.html',
commodity_detail=request.args.get('commodity-detail', '0') == '1', commodity_detail=request.args.get('commodity_detail', '0') == '1',
transactions=sorted(all_transactions(), key=lambda t: t.dt) transactions=sorted(all_transactions(), key=lambda t: t.dt)
) )
@ -82,7 +82,7 @@ def account_transactions():
# FIXME: Filter in SQL # FIXME: Filter in SQL
transactions = [t for t in all_transactions() if any(p.account == request.args['account'] for p in t.postings)] transactions = [t for t in all_transactions() if any(p.account == request.args['account'] for p in t.postings)]
if request.args.get('commodity-detail', '0') == '1': if request.args.get('commodity_detail', '0') == '1':
return render_template( return render_template(
'transactions_commodity_detail.html', 'transactions_commodity_detail.html',
account=request.args['account'], account=request.args['account'],