fix: Add balancing amounts in periodic transactions before applying auto-postings. (#1412)
This commit is contained in:
parent
04a36d4942
commit
2da0e67141
@ -122,8 +122,14 @@ journalAddForecast :: CliOpts -> Journal -> Journal
|
||||
journalAddForecast CliOpts{inputopts_=iopts, reportspec_=rspec} j =
|
||||
case forecast_ ropts of
|
||||
Nothing -> j
|
||||
Just _ -> either (error') id . journalApplyCommodityStyles $ -- PARTIAL:
|
||||
journalBalanceTransactions' iopts j{ jtxns = concat [jtxns j, forecasttxns'] }
|
||||
Just _ -> either error id $ do -- PARTIAL:
|
||||
forecasttxns <- addAutoTxns =<< mapM (balanceTransaction (balancingopts_ iopts))
|
||||
[ txnTieKnot t | pt <- jperiodictxns j
|
||||
, t <- runPeriodicTransaction pt forecastspan
|
||||
, spanContainsDate forecastspan (tdate t)
|
||||
]
|
||||
journalBalanceTransactions (balancingopts_ iopts) j{ jtxns = concat [jtxns j, forecasttxns] }
|
||||
>>= journalApplyCommodityStyles
|
||||
where
|
||||
today = _rsDay rspec
|
||||
ropts = _rsReportOpts rspec
|
||||
@ -141,18 +147,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportspec_=rspec} j =
|
||||
(fromMaybe nulldatespan $ dbg2 "forecastspan flag" $ forecast_ ropts)
|
||||
(DateSpan (Just forecastbeginDefault) (Just forecastendDefault))
|
||||
|
||||
forecasttxns =
|
||||
[ 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 either error' id . modifyTransactions today (jtxnmodifiers j) else id) -- PARTIAL:
|
||||
forecasttxns
|
||||
|
||||
journalBalanceTransactions' iopts j =
|
||||
either error' id $ journalBalanceTransactions (balancingopts_ iopts) j -- PARTIAL:
|
||||
addAutoTxns = if auto_ iopts then modifyTransactions today (jtxnmodifiers j) else return
|
||||
|
||||
-- | Write some output to stdout or to a file selected by --output-file.
|
||||
-- If the file exists it will be overwritten.
|
||||
|
||||
@ -384,3 +384,30 @@ $ hledger -f- print --auto
|
||||
(b) 100 EUR ; generated-posting: = assets amt:>50
|
||||
|
||||
>=0
|
||||
|
||||
# 20. Auto-generated postings apply on auto-balanced periodic postings.
|
||||
<
|
||||
2021-01-01 Fixed
|
||||
Checking -10
|
||||
Costs
|
||||
|
||||
~ 2021-01-02 Periodic
|
||||
Checking -10
|
||||
Costs
|
||||
|
||||
= acct:Costs
|
||||
(Auto) *1
|
||||
|
||||
$ hledger -f- print --forecast --auto --explicit
|
||||
2021-01-01 Fixed ; modified:
|
||||
Checking -10
|
||||
Costs 10
|
||||
(Auto) 10 ; generated-posting: = acct:Costs
|
||||
|
||||
2021-01-02 Periodic
|
||||
; generated-transaction: ~ 2021-01-02, modified:
|
||||
Checking -10
|
||||
Costs 10
|
||||
(Auto) 10 ; generated-posting: = acct:Costs
|
||||
|
||||
>=0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user