From 33d82fb6570cac75f800a1388ca580b5da2f3471 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 1 Feb 2019 11:43:24 -0800 Subject: [PATCH] fix: --forecast shouldn't force --auto on (#953, #959) --- hledger/Hledger/Cli/Utils.hs | 9 +++++---- tests/print/auto.test | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 46d5cd675..1039ec3c7 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -140,7 +140,7 @@ journalApplyValue ropts j = do -- They end on or before the specified report end date, or 180 days from today if unspecified. -- journalAddForecast :: CliOpts -> Journal -> IO Journal -journalAddForecast opts@CliOpts{reportopts_=ropts} j = do +journalAddForecast opts@CliOpts{inputopts_=iopts, reportopts_=ropts} j = do today <- getCurrentDay -- "They start on or after the day following the latest normal transaction in the journal, or today if there are none." @@ -153,15 +153,16 @@ journalAddForecast opts@CliOpts{reportopts_=ropts} j = do let forecastspan = DateSpan (Just forecaststart) (Just forecastend) forecasttxns = - -- If there are forecast transaction, lets apply transaction modifiers to them - modifyTransactions (jtxnmodifiers j) $ [ txnTieKnot t | pt <- jperiodictxns j , t <- runPeriodicTransaction pt forecastspan , spanContainsDate forecastspan (tdate t) ] + -- With --auto enabled, transaction modifiers are also applied to forecast txns + forecasttxns' = (if auto_ iopts then modifyTransactions (jtxnmodifiers j) else id) forecasttxns + return $ if forecast_ ropts - then journalBalanceTransactions' opts j{ jtxns = concat [jtxns j, forecasttxns] } + then journalBalanceTransactions' opts j{ jtxns = concat [jtxns j, forecasttxns'] } else j where journalBalanceTransactions' opts j = diff --git a/tests/print/auto.test b/tests/print/auto.test index 1e9b977c8..faa9c5cf5 100644 --- a/tests/print/auto.test +++ b/tests/print/auto.test @@ -164,7 +164,7 @@ because it is also included in transaction modifiers. >=1 -## Transaction modifiers affect forecast transactions +## Transaction modifiers affect forecast transactions (#959) < = ^income (liabilities:tax) *.33 ; income tax @@ -192,3 +192,17 @@ $ hledger print -f- --auto --forecast -b 2016-01 -e 2016-03 assets:bank >= + +# and they don't force --auto on +$ hledger print -f- --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 + income:donations $-15 + assets:bank + +>=