lib: apply canonical display styles to auto posting amounts too

This commit is contained in:
Simon Michael 2020-01-31 05:57:21 -08:00
parent fccd88149d
commit b3711488a7
2 changed files with 27 additions and 8 deletions

View File

@ -274,9 +274,10 @@ finaliseJournal :: InputOpts -> FilePath -> Text -> Journal -> ExceptT String IO
finaliseJournal iopts f txt pj = do
t <- liftIO getClockTime
-- Infer and apply canonical styles for each commodity (or fail).
-- TODO: since #903's refactoring for hledger 1.12,
-- This affects transaction balancing/assertions/assignments, so needs to be done early.
-- (TODO: since #903's refactoring for hledger 1.12,
-- journalApplyCommodityStyles here is seeing the
-- transactions before they get reversesd to normal order.
-- transactions before they get reversesd to normal order.)
case journalApplyCommodityStyles pj of
Left e -> throwError e
Right pj' -> either throwError return $
@ -292,12 +293,15 @@ finaliseJournal iopts f txt pj = do
else \j -> do -- Either monad
-- Auto postings are active.
-- Balance all transactions without checking balance assertions,
-- then add the auto postings, then check balance assertions.
j' <- journalBalanceTransactions False j
-- then add the auto postings
-- (Note adding auto postings after balancing means #893b fails;
-- adding them before balancing probably means #893a, #928, #938 fail.)
j' <- journalBalanceTransactions False j
let j'' = journalModifyTransactions j'
journalBalanceTransactions (not $ ignore_assertions_ iopts) j''
-- then apply commodity styles once more, to style the auto posting amounts. (XXX inefficient ?)
j''' <- journalApplyCommodityStyles j''
-- then check balance assertions.
journalBalanceTransactions (not $ ignore_assertions_ iopts) j'''
setYear :: Year -> JournalParser m ()
setYear y = modify' (\j -> j{jparsedefaultyear=Just y})

View File

@ -1,5 +1,3 @@
# Transaction modifier adding (unbalanced) tax postings.
# print. Auto-generated postings are inserted below the matched one.
<
= ^income
(liabilities:tax) *.33 ; income tax
@ -13,7 +11,7 @@
assets:cash $20
assets:bank
# 1. print
# 1. print. Auto-generated postings are inserted below the matched one.
$ hledger print -f- --auto
2016-01-01 paycheck ; modified:
income:remuneration $-100
@ -327,3 +325,20 @@ $ hledger -f- register --auto
$ hledger -f- print -x --auto
>2 /could not balance/
>=1
# 17. Commodity display styles are applied to auto posting amounts.
<
2020-01-20
(a) 1 A
; add an auto posting with decimal places
=
(b) *1.5 B
; show B amounts with no decimal places
commodity 0. B
$ hledger -f- print --auto
2020-01-20 ; modified:
(a) 1 A
(b) 2 B ; generated-posting: =
>=0