diff --git a/jarca_ledger_mcp/application/account_valuation_service.py b/jarca_ledger_mcp/application/account_valuation_service.py index 8d50eba..88ab185 100644 --- a/jarca_ledger_mcp/application/account_valuation_service.py +++ b/jarca_ledger_mcp/application/account_valuation_service.py @@ -228,7 +228,7 @@ def select_account_valuation(account_id: str, basis_date: str, as_of: bool = Fal clauses = ["account_id=?"] params: list[Any] = [account_id] if currency: - clauses.append("currency=?"); params.append(currency.strip().upper()) + clauses.append("UPPER(currency)=?"); params.append(currency.strip().upper()) if valuation_kind: clauses.append("valuation_kind=?"); params.append(valuation_kind.strip().lower()) rows = conn.execute(f"SELECT * FROM account_valuations WHERE {' AND '.join(clauses)} ORDER BY basis_date DESC, recorded_at DESC, id DESC", params).fetchall() diff --git a/jarca_ledger_mcp/application/assets_service.py b/jarca_ledger_mcp/application/assets_service.py index 5cc76c2..319fed4 100644 --- a/jarca_ledger_mcp/application/assets_service.py +++ b/jarca_ledger_mcp/application/assets_service.py @@ -91,7 +91,7 @@ def _account_valuation_items(conn: sqlite3.Connection, basis_date: str = "", sel balance = account.get("last_balance") if basis_date: valuation_rows = conn.execute( - "SELECT * FROM account_valuations WHERE account_id=? AND currency=? ORDER BY basis_date DESC, recorded_at DESC, id DESC", + "SELECT * FROM account_valuations WHERE account_id=? AND UPPER(currency)=? ORDER BY basis_date DESC, recorded_at DESC, id DESC", (account["id"], base["currency"]), ).fetchall() leaves = [v for v in valuation_rows if conn.execute("SELECT 1 FROM account_valuations WHERE supersedes_id=?", (v["id"],)).fetchone() is None] diff --git a/tests/test_issue_12_regressions.py b/tests/test_issue_12_regressions.py index e58c2bd..b6a3543 100644 --- a/tests/test_issue_12_regressions.py +++ b/tests/test_issue_12_regressions.py @@ -439,7 +439,12 @@ def test_legacy_lowercase_krw_account_currency_selects_normalized_valuation(tmp_ ) with sqlite3.connect(path) as conn: conn.execute("UPDATE accounts SET currency='krw' WHERE id=?", (account,)) + conn.execute("UPDATE account_valuations SET currency='krw' WHERE account_id=?", (account,)) + selected = service.select_account_valuation( + account, "2026-06-30", currency="KRW", db_path=path, + ) report = service.get_asset_snapshot_report("2026-06-30", db_path=path) + assert selected["valuation"]["amount"] == 100 assert report["total_assets"] == 100 assert report["excluded_items"] == []