default accounting currency

This commit is contained in:
Priec
2026-09-12 19:33:21 +02:00
parent 017ca87c67
commit 156d1c4464
6 changed files with 62 additions and 41 deletions

View File

@@ -59,16 +59,27 @@ impl AccountPathProjection {
});
}
let qualified_accounts = format!(
"\"{}\".\"{}\"",
profile_name.replace('"', "\"\""),
LEDGER_ACCOUNTS_TABLE_NAME,
);
let (schema_id, storage_schema, storage_relation) = sqlx::query_as::<_, (i64, String, String)>(
r#"SELECT profile.id, binding.storage->>'schema', binding.storage->>'relation'
FROM schemas profile
JOIN table_definitions definition ON definition.schema_id = profile.id
JOIN table_storage_bindings binding ON binding.table_definition_id = definition.id
WHERE profile.name = $1 AND definition.table_name = $2
AND definition.table_kind = 'system' AND definition.deleted = FALSE"#,
)
.bind(profile_name)
.bind(LEDGER_ACCOUNTS_TABLE_NAME)
.fetch_optional(pool)
.await
.map_err(|error| Status::internal(format!("Account storage lookup failed: {error}")))?
.ok_or_else(|| Status::failed_precondition("Account tracking is not enabled for profile"))?;
let qualified_accounts = qualify_profile_table(&storage_schema, &storage_relation);
let paths = sqlx::query_as::<_, (i64, String)>(AssertSqlSafe(format!(
"SELECT id, full_path
FROM {qualified_accounts}
WHERE deleted = FALSE"
WHERE schema_id = $1 AND deleted = FALSE"
)))
.bind(schema_id)
.fetch_all(pool)
.await
.map_err(|error| Status::internal(format!("Account path lookup failed: {error}")))?