| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Write.Beancount
Contents
Description
Helpers for beancount output.
Synopsis
- showTransactionBeancount :: Transaction -> Text
- showPriceDirectiveBeancount :: PriceDirective -> Text
- beancountTransactions :: [Transaction] -> [Transaction]
- beancountRenameAccounts :: Journal -> [Transaction] -> (Journal, [Transaction])
- beancountDirectives :: Journal -> [Transaction] -> Text
- beancountItemRenderer :: ItemRenderer
- tagsToBeancountMetadata :: [Tag] -> [BMetadata]
- showBeancountMetadata :: Maybe Int -> BMetadata -> Text
- accountNameToBeancount :: AccountName -> BeancountAccountName
- commodityToBeancount :: CommoditySymbol -> BeancountCommoditySymbol
- tests_WriteBeancount :: TestTree
Documentation
showTransactionBeancount :: Transaction -> Text Source #
Like showTransaction, but applies various adjustments to produce valid Beancount journal data.
showPriceDirectiveBeancount :: PriceDirective -> Text Source #
Render a PriceDirective in Beancount format: DATE price COMMODITY AMOUNT
beancountTransactions :: [Transaction] -> [Transaction] Source #
Prepare transactions for Beancount output: remove virtual postings, and remove conversion postings which are redundant with costs (Beancount doesn't allow both; costs are more useful to it). Assumes at most one cost + conversion postings group per transaction.
beancountRenameAccounts :: Journal -> [Transaction] -> (Journal, [Transaction]) Source #
Rename accounts for Beancount output, in these transactions' postings and in the journal's account declarations: an account whose top-level name is not one of Beancount's required ones is prefixed with the Beancount top-level account corresponding to its hledger account type, if that is known (declared or inferred). Eg with "account bonds ; type:A", bonds:treasury becomes Assets:bonds:treasury (and then Assets:Bonds:Treasury when rendered). Accounts of unknown type are left unchanged, and will raise an error when rendered.
beancountDirectives :: Journal -> [Transaction] -> Text Source #
Options and directives for a Beancount export of this journal and these (Beancount-prepared, possibly filtered) transactions: a sample tolerance option (commented out); operating_currency options for the currencies used in costs; commodity directives for declared commodities, with their tags as metadata; open directives for declared and used accounts, each dated on its earliest posting (or the earliest date overall), with account tags as metadata and a lots: tag as booking method; and price directives, sorted by date. Blank lines separate the sections; the result ends with a newline (or is empty if all sections are empty).
beancountItemRenderer :: ItemRenderer Source #
An item renderer for Beancount output (print --export -O beancount). Transactions are rendered with showTransactionBeancount. Directives are dropped: those with Beancount equivalents are generated by beancountDirectives instead. Comment lines and comment blocks are converted to Beancount (;) comments.
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 and underscores 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, doubles it if less than 2 characters, and disables hledger's enclosing double quotes.
>>>commodityToBeancount """CC">>>commodityToBeancount "$""USD">>>commodityToBeancount "Usd""USD">>>commodityToBeancount "\"a1\"""A1">>>commodityToBeancount "\"A 1!\"""A-1C21">>>commodityToBeancount "K""KK"