hledger-lib-1.42.1: A library providing the core functionality of hledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hledger.Write.Beancount

Contents

Description

Helpers for beancount output.

Synopsis

Documentation

showTransactionBeancount :: Transaction -> Text Source #

Like showTransaction, but applies various adjustments to produce valid Beancount journal data.

tagsToBeancountMetadata :: [Tag] -> [BMetadata] Source #

Make a list of tags ready to be rendered as Beancount metadata: Encode and lengthen names, encode values, and combine repeated tags into one. Metadatas will be sorted by (encoded) name and then value.

showBeancountMetadata :: Maybe Int -> BMetadata -> Text Source #

Render a Beancount metadata as a metadata line (without the indentation or newline). If a maximum name length is provided, space will be left after the colon so that successive metadata values will all start at the same column.

accountNameToBeancount :: AccountName -> BeancountAccountName Source #

Convert a hledger account name to a valid Beancount account name. It replaces spaces with dashes and other non-supported characters with CHEXBYTES; prepends the letter A to any part which doesn't begin with a letter or number; adds a second :A part if there is only one part; and capitalises each part. It also checks that the first part is one of the required english account names Assets, Liabilities, Equity, Income, or Expenses, and if not raises an informative error. Ref: https://beancount.github.io/docs/beancount_language_syntax.html#accounts

commodityToBeancount :: CommoditySymbol -> BeancountCommoditySymbol Source #

Convert a hledger commodity name to a valid Beancount commodity name. That is: 2-24 uppercase letters digits apostrophe period underscore / dash, starting with a letter, and ending with a letter or digit. Ref: https://beancount.github.io/docs/beancount_language_syntax.html#commodities-currencies So this: replaces common currency symbols with their ISO 4217 currency codes, capitalises all letters, replaces spaces with dashes and other invalid characters with CHEXBYTES, prepends a C if the first character is not a letter, appends a C if the last character is not a letter or digit, and disables hledger's enclosing double quotes.

>>> commodityToBeancount ""
"C"
>>> commodityToBeancount "$"
"USD"
>>> commodityToBeancount "Usd"
"USD"
>>> commodityToBeancount "\"a1\""
"A1"
>>> commodityToBeancount "\"A 1!\""
"A-1C21"

Tests