Beancount.Directives.Posting (beancount_ex v0.6.0)

Copy Markdown View Source

A single posting (leg) of a Beancount.Directives.Transaction.

See Costs and Prices in the Beancount syntax guide.

Beancount syntax

Assets:ETrade:IVV   -10 IVV {183.07 USD} @ 197.90 USD
  trade-id: "T-991"

Expenses:Restaurant

A posting may elide amount and currency; Beancount infers them when balancing.

Elixir struct

%Beancount.Directives.Posting{
  account: "Assets:ETrade:IVV",
  amount: Decimal.new("-10"),
  currency: "IVV",
  cost: %Beancount.CostSpec{
    per_amount: Decimal.new("183.07"),
    per_currency: "USD",
    total_amount: nil,
    total_currency: nil,
    date: nil,
    label: nil,
    merge: false
  },
  price: %{amount: Decimal.new("197.90"), currency: "USD", type: :unit},
  flag: nil,
  metadata: %{"trade-id" => "T-991"}
}

Elided amount (inferred by Beancount):

%Beancount.Directives.Posting{
  account: "Expenses:Restaurant",
  amount: nil,
  currency: nil,
  cost: nil,
  price: nil,
  flag: nil,
  metadata: %{}
}

Or use Beancount.posting/4:

Beancount.posting("Assets:ETrade:IVV", Decimal.new("-10"), "IVV",
  cost: %{amount: Decimal.new("183.07"), currency: "USD"},
  price: %{amount: Decimal.new("197.90"), currency: "USD", type: :unit},
  metadata: %{"trade-id" => "T-991"}
)

Fields

  • account - colon-separated account receiving the posting.
  • amount - Decimal.t() units posted, or nil to elide (Beancount interpolates the balancing amount).
  • currency - commodity symbol for amount, or nil when elided.
  • cost - Beancount.CostSpec (or legacy %{amount:, currency:} map) for inventory held at cost, e.g. {183.07 USD}. nil for simple amounts.
  • price - unit price %{amount:, currency:, type: :unit} (@ 1.2 USD) or total price type: :total (@@ 120 USD). nil when absent.
  • flag - optional per-posting flag ("!", etc.) rendered before the account name.
  • metadata - optional map rendered as indented lines under the posting.

Summary

Types

A cost specification. See Beancount.CostSpec.

A price annotation, e.g. @ 1.2 USD or @@ 120 USD.

t()

Types

cost()

@type cost() :: Beancount.CostSpec.t() | map() | nil

A cost specification. See Beancount.CostSpec.

price()

@type price() ::
  %{amount: Decimal.t(), currency: String.t(), type: :unit | :total} | nil

A price annotation, e.g. @ 1.2 USD or @@ 120 USD.

t()

@type t() :: %Beancount.Directives.Posting{
  account: String.t(),
  amount: Decimal.t() | nil,
  cost: cost(),
  currency: String.t() | nil,
  flag: String.t() | nil,
  metadata: map(),
  price: price()
}