diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 2b5d71bdc..2cffcc0c1 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -164,13 +164,16 @@ journalAddForecast opts@CliOpts{reportopts_=ropts} j = do let forecastend = dbg2 "forecastend" $ fromMaybe (addDays 180 today) mspecifiedend let forecastspan = DateSpan (Just forecaststart) (Just forecastend) - forecasttxns = [ txnTieKnot t | pt <- jperiodictxns j - , t <- runPeriodicTransaction pt forecastspan - , spanContainsDate forecastspan (tdate t) - ] + forecasttxns = + -- If there are forecast transaction, lets apply transaction modifiers to them + map (foldr (flip (.) . transactionModifierToFunction) id (jtxnmodifiers j)) $ + [ txnTieKnot t | pt <- jperiodictxns j + , t <- runPeriodicTransaction pt forecastspan + , spanContainsDate forecastspan (tdate t) + ] return $ if forecast_ ropts - then journalBalanceTransactions' opts j{ jtxns = forecasttxns ++ jtxns j } -- XXX wouldn't appending be better ? + then journalBalanceTransactions' opts j{ jtxns = concat [forecasttxns, jtxns j] } else j where journalBalanceTransactions' opts j = diff --git a/tests/print/auto.test b/tests/print/auto.test index b78258c34..1e9b977c8 100644 --- a/tests/print/auto.test +++ b/tests/print/auto.test @@ -164,3 +164,31 @@ because it is also included in transaction modifiers. >=1 +## Transaction modifiers affect forecast transactions +< += ^income + (liabilities:tax) *.33 ; income tax + +~ monthly from 2016-01 paycheck + income:remuneration $-100 + income:donations $-15 + assets:bank + +2016/1/3 withdraw + assets:cash $20 + assets:bank + +$ hledger print -f- --auto --forecast -b 2016-01 -e 2016-03 +2016/01/03 withdraw + assets:cash $20 + assets:bank + +2016/02/01 paycheck + ; recur: monthly from 2016-01 + income:remuneration $-100 + (liabilities:tax) $-33 ; income tax + income:donations $-15 + (liabilities:tax) $-5 ; income tax + assets:bank + +>=