From 04649530f7a4e2109eb0b4edb3066e629327eedf Mon Sep 17 00:00:00 2001 From: NguyenND Date: Tue, 2 Jun 2026 10:09:31 -0400 Subject: [PATCH] 06/02 Modified bank sync, records selectable --- app/routes/teller.py | 20 ++++- app/templates/teller/preview.html | 119 ++++++++++++++++++++++-------- 2 files changed, 105 insertions(+), 34 deletions(-) diff --git a/app/routes/teller.py b/app/routes/teller.py index b0d84d9..769cbef 100644 --- a/app/routes/teller.py +++ b/app/routes/teller.py @@ -199,16 +199,20 @@ def sync_preview_view(teller_account_id): ] session['teller_account_id'] = teller_account_id + from app.models.category import Category + cat_map = {c.id: c.name for c in Category.query.filter_by(is_active=True).all()} + return render_template('teller/preview.html', ta=ta, preview=preview, - count=len(preview)) + count=len(preview), + cat_map=cat_map) @teller_bp.route('/sync/confirm', methods=['POST']) @login_required def sync_confirm(): - """Import the previewed transactions.""" + """Import selected previewed transactions with optional type overrides.""" raw = session.pop('teller_preview', []) ta_id = session.pop('teller_account_id', None) @@ -218,13 +222,23 @@ def sync_confirm(): ta = db.get_or_404(TellerAccount, ta_id) - # Reconstruct parsed list with date objects + selected_ids = set(request.form.getlist('selected')) + from datetime import date as date_cls parsed = [] for r in raw: + if selected_ids and r['teller_id'] not in selected_ids: + continue r['date'] = date_cls.fromisoformat(r['date']) + override = request.form.get(f'type_{r["teller_id"]}') + if override in ('income', 'expense'): + r['transaction_type'] = override parsed.append(r) + if not parsed: + flash('No transactions selected. Nothing was imported.', 'warning') + return redirect(url_for('teller.index')) + imported, skipped = import_transactions(parsed, ta) flash(f'Imported {imported} transaction(s) from {ta.account_name}. ' f'Skipped {skipped} duplicate(s).', 'success') diff --git a/app/templates/teller/preview.html b/app/templates/teller/preview.html index 362b0b2..3d80ab0 100644 --- a/app/templates/teller/preview.html +++ b/app/templates/teller/preview.html @@ -3,65 +3,75 @@ {% block page_title %}Sync Preview — {{ ta.account_name }}{% endblock %} {% block content %} +{% if preview %} +
+ +
{{ ta.institution_name }} — {{ ta.account_name }}
Mapped to: {{ ta.pfm_account.name }} · - {{ count }} transaction(s) found + {{ count }} of {{ count }} selected {% if ta.last_sync_date %}· Last sync: {{ ta.last_sync_date.strftime('%b %d, %Y') }}{% endif %}
Cancel - {% if count > 0 %} - - - - - {% endif %} +
-{% if preview %}
- + + - + {% for txn in preview %} - - + + - {% endfor %} @@ -70,14 +80,13 @@
-
- - - +
+ + {% else %}
@@ -86,4 +95,52 @@ Back
{% endif %} + + {% endblock %}
Date + + Date DescriptionTypeType Category Amount
+
+ + {{ txn.date.strftime('%b %d, %Y') }} {{ txn.description }} - - {{ txn.transaction_type | title }} - + - {% if txn.category_id %} - {% for cat in [txn.category_id] %} - {# Look up category name via the category_id #} - {{ txn.notes | replace('Teller:', '') }} - {% endfor %} + {% if txn.category_id and txn.category_id in cat_map %} + {{ cat_map[txn.category_id] }} {% else %} - Uncategorised + Uncategorised {% endif %} - {% if txn.transaction_type == 'income' %}+{% else %}-{% endif %}{{ txn.amount | currency }} + {% if txn.transaction_type == 'income' %}+{% else %}-{% endif %}{{ txn.amount | currency }}