;run: --forecast with changed reporting interval fix (+test) [#2345]
This commit is contained in:
parent
542d1802ee
commit
c0b3c932ea
@ -43,6 +43,7 @@ import Hledger.Cli.DocFiles (runTldrForPage, runInfoForTopic, runManForTopic)
|
|||||||
import Hledger.Cli.Utils (journalTransform)
|
import Hledger.Cli.Utils (journalTransform)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import System.Process (system)
|
import System.Process (system)
|
||||||
|
import Data.Maybe (isJust)
|
||||||
|
|
||||||
-- | Command line options for this command.
|
-- | Command line options for this command.
|
||||||
runmode = hledgerCommandMode
|
runmode = hledgerCommandMode
|
||||||
@ -240,10 +241,9 @@ withJournalCached defaultJournalOverride cliopts cmd = do
|
|||||||
either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal
|
either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal
|
||||||
where
|
where
|
||||||
-- InputOptions contain reportspan_ that is used to calculare forecast period,
|
-- InputOptions contain reportspan_ that is used to calculare forecast period,
|
||||||
-- that is used by journalFinalise to insert forecast transactions.addHeaderBorders
|
-- that is used by journalFinalise to insert forecast transactions.
|
||||||
-- For the purposes of caching, we want to ignore this, as it is only used for forecast
|
-- For the purposes of caching, we want to ignore this when --forecast is not given.
|
||||||
-- and it is sufficient to include forecast_ in the InputOptions that we use as a key.
|
ioptsWithoutReportSpan = if isJust (forecast_ iopts) then iopts else iopts { reportspan_ = emptydatespan }
|
||||||
ioptsWithoutReportSpan = iopts { reportspan_ = emptydatespan }
|
|
||||||
-- Read stdin, or if we read it alread, use a cache
|
-- Read stdin, or if we read it alread, use a cache
|
||||||
-- readStdin :: InputOpts -> ExceptT String IO Journal
|
-- readStdin :: InputOpts -> ExceptT String IO Journal
|
||||||
readStdin = do
|
readStdin = do
|
||||||
|
|||||||
@ -164,3 +164,33 @@ readAndCacheJournalFile reading and caching -:
|
|||||||
readAndCacheJournalFile reading and caching sample.journal:
|
readAndCacheJournalFile reading and caching sample.journal:
|
||||||
readAndCacheJournalFile using cache for -:
|
readAndCacheJournalFile using cache for -:
|
||||||
readAndCacheJournalFile using cache for sample.journal:
|
readAndCacheJournalFile using cache for sample.journal:
|
||||||
|
|
||||||
|
# ** 12. Run commands with forecast properly honor reporting interval
|
||||||
|
<
|
||||||
|
2025-01-01 Buy beans
|
||||||
|
expenses:food $2
|
||||||
|
assets -$2
|
||||||
|
|
||||||
|
~ every 14 days from 2025-01-01 Buy soylent green
|
||||||
|
expenses:food:not people $1
|
||||||
|
assets -$1
|
||||||
|
$ hledger run -f- -- echo "Till Feb" -- register --forecast -b 2025-01 -e 2025-02 -- echo "Till Mar" -- register --forecast -b 2025-01 -e 2025-03
|
||||||
|
>
|
||||||
|
Till Feb
|
||||||
|
2025-01-01 Buy beans expenses:food $2 $2
|
||||||
|
assets $-2 0
|
||||||
|
2025-01-15 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
2025-01-29 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
Till Mar
|
||||||
|
2025-01-01 Buy beans expenses:food $2 $2
|
||||||
|
assets $-2 0
|
||||||
|
2025-01-15 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
2025-01-29 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
2025-02-12 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
2025-02-26 Buy soylent green ex:food:not people $1 $1
|
||||||
|
assets $-1 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user