Skip to content

Commit 1f2dc55

Browse files
David AlvesDavid Alves
authored andcommitted
Merge feat/skip-pending-toggle: per-account skip-pending toggle (#17)
2 parents e2ff923 + 710f9c4 commit 1f2dc55

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

app/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _ensure_tables(conn):
5252
("provider_credentials", "ALTER TABLE bank_accounts ADD COLUMN provider_credentials TEXT DEFAULT ''"),
5353
("sync_mode", "ALTER TABLE bank_accounts ADD COLUMN sync_mode TEXT NOT NULL DEFAULT 'transactions'"),
5454
("license_seat_id", "ALTER TABLE bank_accounts ADD COLUMN license_seat_id TEXT"),
55+
("skip_pending", "ALTER TABLE bank_accounts ADD COLUMN skip_pending INTEGER NOT NULL DEFAULT 0"),
5556
]:
5657
try:
5758
conn.execute(sql)
@@ -198,7 +199,7 @@ def get_bank_account(account_id: int):
198199
return dict(row) if row else None
199200

200201
def update_bank_account_field(account_id: int, field: str, value: str):
201-
allowed = {"start_sync_date", "session_id", "account_uid", "session_expiry", "actual_account", "bank_name", "bank_country", "provider", "provider_credentials", "sync_mode", "license_seat_id"}
202+
allowed = {"start_sync_date", "session_id", "account_uid", "session_expiry", "actual_account", "bank_name", "bank_country", "provider", "provider_credentials", "sync_mode", "license_seat_id", "skip_pending"}
202203
if field not in allowed:
203204
raise ValueError(f"Field {field} is not updatable")
204205
with _conn() as conn:

app/sync.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,14 @@ def _sync_account(account, state):
329329
already_matched = existing[:]
330330
new_txn = []
331331

332+
skip_pending = bool(account.get("skip_pending"))
333+
332334
for txn in raw:
333335
try:
334336
status = txn.get("status", "BOOK")
337+
if status == "PDNG" and skip_pending:
338+
skipped += 1
339+
continue
335340
date = _parse_date(txn)
336341
amount = _parse_amount(txn)
337342
payee = _parse_payee(txn)

app/web/server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,15 @@ def disconnect():
10271027
logger.warning("Failed to release bank seat for %s: %s", account.get("bank_name"), result.get("error"))
10281028
return redirect(url_for("bank"))
10291029

1030+
@app.route("/toggle-skip-pending", methods=["POST"])
1031+
def toggle_skip_pending():
1032+
account_id = request.form.get("account_id")
1033+
if account_id:
1034+
skip = "1" if request.form.get("skip_pending") == "1" else "0"
1035+
db.update_bank_account_field(int(account_id), "skip_pending", skip)
1036+
logger.info("Set skip_pending=%s for account %s", skip, account_id)
1037+
return redirect(url_for("bank"))
1038+
10301039
@app.route("/reset-sync", methods=["POST"])
10311040
def reset_sync():
10321041
account_id = request.form.get("account_id")

app/web/templates/bank.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@
101101
</form>
102102
</div>
103103
{% endif %}
104+
{% if a.sync_mode != 'balance' %}
105+
<div style="margin-top:8px;font-size:11px;color:#4a5568;">
106+
<form method="POST" action="/toggle-skip-pending" style="display:inline;" id="skip-pending-form-{{ a.id }}">
107+
<input type="hidden" name="account_id" value="{{ a.id }}">
108+
<input type="hidden" name="skip_pending" value="{{ '0' if a.skip_pending else '1' }}">
109+
<label style="display:inline-flex;align-items:center;gap:6px;cursor:pointer;margin:0;">
110+
<input type="checkbox" {% if a.skip_pending %}checked{% endif %} onchange="document.getElementById('skip-pending-form-{{ a.id }}').submit();" style="cursor:pointer;margin:0;">
111+
<span>Only sync booked transactions (skip pending)</span>
112+
</label>
113+
</form>
114+
</div>
115+
{% endif %}
104116
</div>
105117
{% endfor %}
106118
<hr style="border:none;border-top:1px solid #253450;margin:1.25rem 0;">

0 commit comments

Comments
 (0)