feat: Buchungs-Pagination, Inbox-Scan-Button, Grafana-Direktansteuerung, UI-Feinschliff
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,10 +19,12 @@ from app.routers.planning import list_planned as _list_planned
|
||||
from app.routers.planning import list_recurring as _list_recurring
|
||||
from app.routers.planning import recurring_suggestions as _recurring_suggestions
|
||||
from app.routers.scenarios import list_scenarios as _list_scenarios
|
||||
from app.routers.transactions import list_transactions
|
||||
from app.routers.transactions import count_transactions, list_transactions
|
||||
from app.services.balances import account_balance, total_balance
|
||||
from app.version import get_version
|
||||
|
||||
PAGE_SIZE = 50
|
||||
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
templates.env.globals["app_version"] = get_version()
|
||||
router = APIRouter()
|
||||
@@ -81,8 +83,21 @@ def buchungen(
|
||||
category_id: int | None = None,
|
||||
q: str | None = None,
|
||||
status: str = "confirmed",
|
||||
page: int = 1,
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
page = max(1, page)
|
||||
total = count_transactions(
|
||||
account_id=account_id,
|
||||
date_from=date_from,
|
||||
date_to=date_to,
|
||||
category_id=category_id,
|
||||
q=q,
|
||||
status=status,
|
||||
session=session,
|
||||
)
|
||||
total_pages = max(1, -(-total // PAGE_SIZE)) # ceil division
|
||||
page = min(page, total_pages)
|
||||
txs = list_transactions(
|
||||
account_id=account_id,
|
||||
date_from=date_from,
|
||||
@@ -90,8 +105,8 @@ def buchungen(
|
||||
category_id=category_id,
|
||||
q=q,
|
||||
status=status,
|
||||
limit=200,
|
||||
offset=0,
|
||||
limit=PAGE_SIZE,
|
||||
offset=(page - 1) * PAGE_SIZE,
|
||||
session=session,
|
||||
)
|
||||
accounts = session.execute(select(Account)).scalars().all()
|
||||
@@ -108,6 +123,8 @@ def buchungen(
|
||||
"q": q or "",
|
||||
"status": status,
|
||||
},
|
||||
"page": page,
|
||||
"total_pages": total_pages,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from decimal import Decimal
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy import func, or_, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.auth import require_auth
|
||||
@@ -46,19 +46,18 @@ class TransactionPatch(BaseModel):
|
||||
category_id: int | None = None
|
||||
|
||||
|
||||
@router.get("", response_model=list[TransactionOut])
|
||||
def list_transactions(
|
||||
def _apply_transaction_filters(
|
||||
stmt,
|
||||
account_id: int | None = None,
|
||||
date_from: date | None = None,
|
||||
date_to: date | None = None,
|
||||
category_id: int | None = None,
|
||||
q: str | None = None,
|
||||
status: str = "confirmed",
|
||||
limit: int = 200,
|
||||
offset: int = 0,
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
stmt = select(Transaction)
|
||||
"""Wendet die Buchungs-Filter auf ein select()-Statement an. Wird sowohl fuer
|
||||
die Liste als auch fuer die dazugehoerige Gesamtanzahl (Pagination) genutzt,
|
||||
damit beide garantiert dieselben Ergebnisse zaehlen/zeigen."""
|
||||
if status:
|
||||
stmt = stmt.where(Transaction.status == status)
|
||||
if account_id is not None:
|
||||
@@ -73,10 +72,47 @@ def list_transactions(
|
||||
like = f"%{q}%"
|
||||
stmt = stmt.where(or_(Transaction.purpose.ilike(like),
|
||||
Transaction.counterparty.ilike(like)))
|
||||
return stmt
|
||||
|
||||
|
||||
@router.get("", response_model=list[TransactionOut])
|
||||
def list_transactions(
|
||||
account_id: int | None = None,
|
||||
date_from: date | None = None,
|
||||
date_to: date | None = None,
|
||||
category_id: int | None = None,
|
||||
q: str | None = None,
|
||||
status: str = "confirmed",
|
||||
limit: int = 200,
|
||||
offset: int = 0,
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
stmt = _apply_transaction_filters(
|
||||
select(Transaction), account_id=account_id, date_from=date_from,
|
||||
date_to=date_to, category_id=category_id, q=q, status=status,
|
||||
)
|
||||
stmt = stmt.order_by(Transaction.booking_date, Transaction.id).offset(offset).limit(limit)
|
||||
return [TransactionOut.model_validate(t) for t in session.execute(stmt).scalars()]
|
||||
|
||||
|
||||
def count_transactions(
|
||||
account_id: int | None = None,
|
||||
date_from: date | None = None,
|
||||
date_to: date | None = None,
|
||||
category_id: int | None = None,
|
||||
q: str | None = None,
|
||||
status: str = "confirmed",
|
||||
session: Session = Depends(get_session),
|
||||
) -> int:
|
||||
"""Gesamtanzahl der Buchungen fuer die gleichen Filter wie list_transactions
|
||||
(ohne limit/offset) - Grundlage fuer die Seitenzahl in der GUI-Pagination."""
|
||||
stmt = _apply_transaction_filters(
|
||||
select(func.count(Transaction.id)), account_id=account_id, date_from=date_from,
|
||||
date_to=date_to, category_id=category_id, q=q, status=status,
|
||||
)
|
||||
return session.execute(stmt).scalar_one()
|
||||
|
||||
|
||||
@router.post("", response_model=TransactionOut, status_code=201)
|
||||
def create_transaction(data: TransactionIn, session: Session = Depends(get_session)):
|
||||
if session.get(Account, data.account_id) is None:
|
||||
|
||||
@@ -144,6 +144,10 @@ button {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
section.planning-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
@@ -155,5 +159,6 @@ section.planning-section fieldset {
|
||||
.version {
|
||||
margin-top: 2rem;
|
||||
color: #888;
|
||||
font-size: 0.85rem;
|
||||
text-align: center;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
@@ -34,12 +34,20 @@
|
||||
hx-on::after-request="if(event.detail.successful){htmx.trigger(document.getElementById('imports'), 'refresh')}">
|
||||
<button type="submit">Übernehmen</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form class="inline-form" hx-delete="/api/imports/{{ s.id }}" hx-swap="none"
|
||||
hx-confirm="Import „{{ s.filename }}“ wirklich verwerfen?"
|
||||
hx-on::after-request="if(event.detail.successful){htmx.trigger(document.getElementById('imports'), 'refresh')}">
|
||||
<button type="submit">Verwerfen</button>
|
||||
</form>
|
||||
{% elif s.status == "confirmed" %}
|
||||
<span class="muted">Bestätigt — Buchungen übernommen</span>
|
||||
{% else %}
|
||||
<form class="inline-form" hx-delete="/api/imports/{{ s.id }}" hx-swap="none"
|
||||
hx-confirm="Import „{{ s.filename }}“ wirklich verwerfen?"
|
||||
hx-on::after-request="if(event.detail.successful){htmx.trigger(document.getElementById('imports'), 'refresh')}">
|
||||
<button type="submit">Verwerfen</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
Kontoauszug-PDF hier ablegen oder klicken zum Hochladen
|
||||
<input type="file" id="file-input" accept="application/pdf" style="display:none">
|
||||
</div>
|
||||
<button type="button" hx-post="/api/imports/scan-inbox" hx-swap="none"
|
||||
hx-on::after-request="if(event.detail.successful){htmx.trigger(document.getElementById('imports'), 'refresh')}">
|
||||
Inbox scannen
|
||||
</button>
|
||||
<p class="muted">Durchsucht <code>~/.local/share/finance_pod/data/inbox/</code> nach neuen PDF-Kontoauszügen.</p>
|
||||
<p id="upload-message"></p>
|
||||
|
||||
<h2>Importe</h2>
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</table>
|
||||
|
||||
<h2>Grafana-Dashboard</h2>
|
||||
<iframe class="grafana" src="http://{{ request.url.hostname or '127.0.0.1' }}:8097"></iframe>
|
||||
<iframe class="grafana" src="http://{{ request.url.hostname or '127.0.0.1' }}:8097/d/finanzen/finanzen?orgId=1&kiosk"></iframe>
|
||||
<p class="hint">Kein Diagramm sichtbar? Einmal in
|
||||
<a href="http://{{ request.url.hostname or '127.0.0.1' }}:8097" target="_blank">Grafana anmelden</a>
|
||||
(gleiches Passwort wie hier).</p>
|
||||
|
||||
@@ -87,6 +87,24 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="pager">
|
||||
{% set pager_params = {
|
||||
'account_id': filters.account_id,
|
||||
'date_from': filters.date_from.isoformat() if filters.date_from else None,
|
||||
'date_to': filters.date_to.isoformat() if filters.date_to else None,
|
||||
'category_id': filters.category_id,
|
||||
'q': filters.q,
|
||||
'status': filters.status,
|
||||
} %}
|
||||
{% if page > 1 %}
|
||||
<a href="/buchungen?{% for k, v in pager_params.items() %}{% if v %}{{ k }}={{ v|urlencode }}&{% endif %}{% endfor %}page={{ page - 1 }}">Zurück</a>
|
||||
{% endif %}
|
||||
Seite {{ page }} von {{ total_pages }}
|
||||
{% if page < total_pages %}
|
||||
<a href="/buchungen?{% for k, v in pager_params.items() %}{% if v %}{{ k }}={{ v|urlencode }}&{% endif %}{% endfor %}page={{ page + 1 }}">Weiter</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<fieldset>
|
||||
<legend>Buchung manuell erfassen</legend>
|
||||
<form hx-ext="json-form" hx-post="/api/transactions" hx-swap="none"
|
||||
|
||||
Reference in New Issue
Block a user