Logistiki.Knowledge.TemplateResolver (logistiki v0.1.0)

Copy Markdown View Source

Resolves the posting template for a selected accounting policy.

A template is a list of posting specs (%{sequence, direction, role, amount_var, currency_var}). The journal builder turns a template plus resolved account roles into concrete postings.

Summary

Functions

Resolves the template postings for normalized_event's selected policy.

Resolves the concrete account code for role from account_roles.

Functions

resolve(normalized_event)

(since 0.1.0)
@spec resolve(Logistiki.Event.Normalized.t()) ::
  {:ok, Logistiki.Knowledge.Result.t(), [map()]}
  | {:error, :no_template_found | term()}

Resolves the template postings for normalized_event's selected policy.

Arguments

  • normalized_event%Logistiki.Event.Normalized{}.

Returns

  • {:ok, %Result{}, [posting_spec]} — the full knowledge result and the ordered posting specs for the selected policy.
  • {:error, :no_template_found} — the selected policy has no template.
  • {:error, term()} — knowledge evaluation failed.

Examples

iex> {:ok, result, postings} = Logistiki.Knowledge.TemplateResolver.resolve(normalized_deposit)
iex> length(postings)
2
iex> hd(postings).role
:cash_account

resolve_account_role(account_roles, role)

(since 0.1.0)
@spec resolve_account_role(map(), atom()) ::
  {:ok, String.t()} | {:error, {:missing_account_role, atom()}}

Resolves the concrete account code for role from account_roles.

Arguments

  • account_rolesmap() — the role-to-code map from a Result (e.g. %{cash_account: "ASSETS:CASH:USD:NOSTRO"}).
  • roleatom() — the symbolic role (e.g. :cash_account).

Returns

  • {:ok, String.t()} — the resolved account code.
  • {:error, {:missing_account_role, role}} — no mapping for this role.

Examples

iex> {:ok, "ASSETS:CASH:USD:NOSTRO"} = Logistiki.Knowledge.TemplateResolver.resolve_account_role(
...>   %{cash_account: "ASSETS:CASH:USD:NOSTRO"}, :cash_account
...> )
iex> {:error, {:missing_account_role, :unknown_role}} = Logistiki.Knowledge.TemplateResolver.resolve_account_role(%{}, :unknown_role)