Skip to content

feat: financial data integrity & reconciliation (#96)#481

Closed
sinatragianpaolo-oc wants to merge 2 commits intorohitdash08:mainfrom
sinatragianpaolo-oc:feat/financial-integrity-reconciliation
Closed

feat: financial data integrity & reconciliation (#96)#481
sinatragianpaolo-oc wants to merge 2 commits intorohitdash08:mainfrom
sinatragianpaolo-oc:feat/financial-integrity-reconciliation

Conversation

@sinatragianpaolo-oc
Copy link

Implements financial data integrity & reconciliation to fix #96.

Detects missing or inconsistent financial records across 8 check categories. All checks are read-only — nothing is mutated.

Endpoints

GET /integrity/check?months=3 — full report with all detail arrays
GET /integrity/check/summary — lightweight status + per-check counts (for dashboard badges)

Both JWT-protected.

Checks performed

Check Severity Description
balance_mismatches warning Months where expenses > income (negative net flow)
orphaned_expenses error Expenses referencing a deleted/missing category
orphaned_recurring error Recurring expenses referencing a missing category
future_dated_expenses warning Expenses with spent_at > today (likely data entry error)
duplicate_expenses warning Same-day/amount/type expenses (likely double-entry)
negative_amounts error Expenses with amount <= 0
stale_recurring warning Active recurring expenses past their end_date
bills_missing_reminders warning Active bills due within 7 days with no pending reminder

overall_status: "ok" / "warnings" / "errors"

Example response

{
  "overall_status": "warnings",
  "total_issues": 3,
  "balance_mismatches": [{"month": "2026-02", "income": 1000, "expenses": 2500, "net_flow": -1500}],
  "future_dated_expenses": [{"expense_id": 42, "days_ahead": 5}],
  "bills_missing_reminders": [{"bill_name": "Rent", "days_until_due": 2}],
  ...
}

Files

  • app/services/integrity.py — 8 check functions + run_integrity_check(uid, months)
  • app/routes/integrity.py — Flask blueprint
  • app/routes/__init__.py — blueprint registration
  • tests/test_integrity.py — 35 tests (service unit + HTTP integration)

/claim #96

Closes #96

Gianpaolo added 2 commits March 17, 2026 02:59
…ohitdash08#96)

8 integrity checks:
  - balance mismatch (monthly net flow < 0)
  - orphaned expenses (missing category_id)
  - orphaned recurring expenses (missing category_id)
  - future-dated expenses (spent_at > today)
  - duplicate expenses (same day/amount/type)
  - negative amounts
  - stale active recurring (end_date passed)
  - bills missing reminders (due within 7 days)

Endpoints:
  GET /integrity/check?months=3  — full report, all check arrays
  GET /integrity/check/summary   — overall_status + per-check counts only

All checks are read-only. Graceful degradation: duplicate check uses
array_agg (PostgreSQL-only); falls back silently on SQLite.
Unit tests: empty DB → ok, balance mismatch, orphaned expense, future-dated,
negative amount, stale recurring, bill missing reminder, user isolation.
HTTP tests: auth, structure, clean user → ok, months param/validation,
future expense via HTTP, balance via HTTP.
Summary endpoint: auth, keys, no detail arrays.
@sinatragianpaolo-oc
Copy link
Author

Closing in favour of #478 which covers the same issue (#96) with a more complete implementation. Please review #478 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Financial Data Integrity & Reconciliation

1 participant