Logistiki.Ledger.BeancountMapper (logistiki v0.1.0)

Copy Markdown View Source

Maps Logistiki virtual accounts, journals, and postings to Beancount directives and back.

Beancount is the accounting oracle, not the domain model. Beancount-specific structs never escape this module (and the Logistiki.Ledger.Beancount backend). The public API only sees Logistiki.Projections.* structs.

Account code mapping

Logistiki virtual account codes are colon-separated and human-readable (LIABILITIES:CLIENT_DEPOSITS:USD:ACME:OPERATING). The mapper produces deterministic Beancount account names by mapping the account type to a Beancount root (Assets, Liabilities, Equity, Income, Expenses) and CamelCasing the remaining segments.

Summary

Functions

Converts a Beancount balances result into a map of account -> balance.

Converts a Beancount query row into a plain map of column -> value.

True when the account type has a debit normal balance.

Returns the beancount root for a Logistiki account type.

Returns the signed Beancount amount for a Logistiki posting.

Maps a %VirtualAccount{} to a deterministic Beancount account name.

Maps a Logistiki journal + postings + accounts to a Beancount transaction directive.

Maps a list of accounts to Beancount open directives.

Maps a Logistiki posting to a Beancount posting (signed amount).

Functions

from_beancount_balance(err)

(since 0.1.0)

Converts a Beancount balances result into a map of account -> balance.

from_beancount_entry(result)

(since 0.1.0)

Converts a Beancount query row into a plain map of column -> value.

normal_debit?(type)

(since 0.1.0)

True when the account type has a debit normal balance.

root_for_type(type)

(since 0.1.0)

Returns the beancount root for a Logistiki account type.

signed_amount(posting, account)

(since 0.1.0)

Returns the signed Beancount amount for a Logistiki posting.

Beancount encodes direction as sign: debits are positive, credits are negative, regardless of account type. Account balances then read naturally (assets positive, liabilities/income negative) and match Logistiki's net = debit - credit projection.

to_beancount_account(virtual_account)

(since 0.1.0)

Maps a %VirtualAccount{} to a deterministic Beancount account name.

to_beancount_directive(journal, postings, accounts_by_code)

(since 0.1.0)

Maps a Logistiki journal + postings + accounts to a Beancount transaction directive.

to_beancount_opens(accounts, date \\ ~D[2026-01-01])

(since 0.1.0)

Maps a list of accounts to Beancount open directives.

to_beancount_posting(posting, account)

(since 0.1.0)

Maps a Logistiki posting to a Beancount posting (signed amount).