diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 65c95c1de..83ae4b472 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -148,11 +148,15 @@ journalAddForecast CliOpts{inputopts_=iopts, reportopts_=ropts} j = do either error' id $ journalBalanceTransactions assrt j -- PARTIAL: where assrt = not . ignore_assertions_ $ iopts - let j' = case forecast_ ropts of - Just _ -> journalBalanceTransactions' iopts j{ jtxns = concat [jtxns j, forecasttxns'] } - Nothing -> j - - return j' + case forecast_ ropts of + Nothing -> return j + Just _ -> do + let j' = journalBalanceTransactions' iopts j{ jtxns = concat [jtxns j, forecasttxns'] } + -- Display styles were applied early.. apply them again to ensure the forecasted + -- transactions are also styled. XXX Possible optimisation: style just the forecasttxns. + case journalApplyCommodityStyles j' of + Left e -> error' e -- PARTIAL: + Right j'' -> return j'' -- | Write some output to stdout or to a file selected by --output-file. -- If the file exists it will be overwritten. diff --git a/tests/forecast.test b/tests/forecast.test index 580d9815a..d00a2bfd0 100644 --- a/tests/forecast.test +++ b/tests/forecast.test @@ -201,3 +201,20 @@ unexpected 'f' expecting end of input (use -h to see usage) >>>=1 + +# 10. Amount display style is applied to forecasted transactions. +hledger -f - reg --forecast date:202001 +<<< +commodity 1,000.00 USD + +2020-01-01 + (a) 1,000.00 USD + +~ every 28th day + (a) 1000.00 USD + +>>> +2020-01-01 (a) 1,000.00 USD 1,000.00 USD +2020-01-28 (a) 1,000.00 USD 2,000.00 USD +>>>2 +>>>=0