From 0b8e920810751e0e18b03b326ace74073622d232 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 22 Nov 2023 23:54:10 -1000 Subject: [PATCH] imp:print:beancount: also convert cost amounts --- hledger-lib/Hledger/Data/Posting.hs | 8 ++++++-- hledger/Hledger/Cli/Commands/Print.md | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 84b3e3d58..01461e3e6 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -386,12 +386,16 @@ type BeancountAmount = Amount -- in a way that Beancount can read: forces the commodity symbol to the right, -- converts $ to USD. amountToBeancount :: Amount -> BeancountAmount -amountToBeancount a@Amount{acommodity=c,astyle=s} = a{acommodity=c', astyle=s'} +amountToBeancount a@Amount{acommodity=c,astyle=s,aprice=mp} = a{acommodity=c', astyle=s', aprice=mp'} -- https://beancount.github.io/docs/beancount_language_syntax.html#commodities-currencies where - s' = s{ascommodityside=R, ascommodityspaced=True} c' | c=="$" = "USD" | otherwise = c + s' = s{ascommodityside=R, ascommodityspaced=True} + mp' = costToBeancount <$> mp + where + costToBeancount (TotalPrice amt) = TotalPrice $ amountToBeancount amt + costToBeancount (UnitPrice amt) = UnitPrice $ amountToBeancount amt -- | Like showAccountName for Beancount journal format. -- Calls accountNameToBeancount first. diff --git a/hledger/Hledger/Cli/Commands/Print.md b/hledger/Hledger/Cli/Commands/Print.md index 65d2a95b5..b2934c615 100644 --- a/hledger/Hledger/Cli/Commands/Print.md +++ b/hledger/Hledger/Cli/Commands/Print.md @@ -121,8 +121,8 @@ The output formats supported are The `beancount` format tries to produce Beancount-compatible output. It is very basic and may require additional manual fixups: -- Transaction and postings with unmarked status are converted to cleared (`*``) status. -- Transactions' payee and or note are wrapped in double quotes. +- Transaction and postings with unmarked status are converted to cleared (`*`) status. +- Transactions' payee and note are wrapped in double quotes. - Transaction tags are copied to Beancount #tag format. - Account name parts are capitalised, and if the first account name part is not one of Assets, Liabilities, Equity, Income, or Expenses, "Equity:" is prepended.