imp:print:beancount: remove virtual postings automatically
This commit is contained in:
parent
b68ebc221b
commit
6e3dfd6703
@ -21,7 +21,3 @@
|
||||
# Print beancount output by default.
|
||||
[print]
|
||||
-O beancount
|
||||
|
||||
# Exclude transactions containing unbalanced/virtual postings.
|
||||
# You might need to do more if you have mixed balanced/unbalanced transactions.
|
||||
--real
|
||||
|
||||
@ -43,7 +43,7 @@ import Data.Function ((&))
|
||||
-- $setup
|
||||
-- >>> :set -XOverloadedStrings
|
||||
|
||||
-- | Like showTransaction, but generates Beancount journal format.
|
||||
-- | Like showTransaction, but applies various adjustments to produce valid Beancount journal data.
|
||||
showTransactionBeancount :: Transaction -> Text
|
||||
showTransactionBeancount t =
|
||||
-- https://beancount.github.io/docs/beancount_language_syntax.html
|
||||
|
||||
@ -181,23 +181,22 @@ entriesReportAsText = entriesReportAsTextHelper showTransaction
|
||||
entriesReportAsTextHelper :: (Transaction -> T.Text) -> EntriesReport -> TL.Text
|
||||
entriesReportAsTextHelper showtxn = TB.toLazyText . foldMap (TB.fromText . showtxn)
|
||||
|
||||
-- In addition to rendering the transactions in (best effort) Beancount format,
|
||||
-- this generates an account open directive for each account name used
|
||||
-- (using the earliest transaction date).
|
||||
-- This transforms transactions in various ways (see Beancount.hs) to make them Beancount-compatible.
|
||||
-- It also generates an account open directive for each account used (on their earliest transaction dates).
|
||||
entriesReportAsBeancount :: EntriesReport -> TL.Text
|
||||
entriesReportAsBeancount ts =
|
||||
-- PERF: gathers and converts all account names, then repeats that work when showing each transaction
|
||||
opendirectives <> "\n" <>
|
||||
entriesReportAsTextHelper showTransactionBeancount ts
|
||||
opendirectives <> "\n" <> entriesReportAsTextHelper showTransactionBeancount allrealts
|
||||
where
|
||||
allrealts = [t{tpostings=filter isReal $ tpostings t} | t <- ts]
|
||||
opendirectives
|
||||
| null ts = ""
|
||||
| otherwise = TL.fromStrict $ T.unlines [
|
||||
firstdate <> " open " <> accountNameToBeancount a
|
||||
| a <- nubSort $ concatMap (map paccount.tpostings) ts
|
||||
| a <- nubSort $ concatMap (map paccount.tpostings) allrealts
|
||||
]
|
||||
where
|
||||
firstdate = showDate $ minimumDef err $ map tdate ts
|
||||
firstdate = showDate $ minimumDef err $ map tdate allrealts
|
||||
where err = error' "entriesReportAsBeancount: should not happen"
|
||||
|
||||
entriesReportAsSql :: EntriesReport -> TL.Text
|
||||
|
||||
@ -860,10 +860,8 @@ and prepend/append a "C" when needed.
|
||||
|
||||
#### Beancount virtual postings
|
||||
|
||||
Beancount doesn't allow [unbalanced/virtual postings](#virtual-postings),
|
||||
so you will need to comment those,
|
||||
or use `--real` to exclude transactions that use them.
|
||||
(If you have transactions which are a mixture of balanced and unbalanced postings, you'll have to do something more.)
|
||||
Beancount doesn't allow [virtual postings](#virtual-postings);
|
||||
if you have any, they will not appear in beancount output.
|
||||
|
||||
#### Beancount costs
|
||||
|
||||
|
||||
@ -44,3 +44,18 @@ $ hledger -f- print -O beancount
|
||||
|
||||
>=
|
||||
|
||||
# ** 4. Virtual postings are dropped.
|
||||
<
|
||||
2000-01-01
|
||||
Assets 0 USD
|
||||
(a) 1
|
||||
[b] 2
|
||||
[c]
|
||||
|
||||
$ hledger -f- print -O beancount
|
||||
2000-01-01 open Assets
|
||||
|
||||
2000-01-01 *
|
||||
Assets 0 USD
|
||||
|
||||
>=
|
||||
|
||||
Loading…
Reference in New Issue
Block a user