ref: journalFinalise: clarify sequence, top to bottom
This commit is contained in:
parent
91441bad8f
commit
885a4fcfec
@ -317,42 +317,28 @@ parseAndFinaliseJournal' parser iopts f txt = do
|
|||||||
-- - check all commodities have been declared if in strict mode
|
-- - check all commodities have been declared if in strict mode
|
||||||
--
|
--
|
||||||
journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal
|
journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal
|
||||||
journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_} f txt pj = do
|
journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_,_ioDay} f txt pj = do
|
||||||
t <- liftIO getPOSIXTime
|
t <- liftIO getPOSIXTime
|
||||||
-- Infer and apply canonical styles for each commodity (or throw an error).
|
liftEither $ do
|
||||||
-- This affects transaction balancing/assertions/assignments, so needs to be done early.
|
let pj2 = pj
|
||||||
liftEither $ checkAddAndBalance (_ioDay iopts) <=< journalApplyCommodityStyles $
|
& journalSetLastReadTime t -- save the last read time
|
||||||
pj{jglobalcommoditystyles=fromMaybe mempty $ commodity_styles_ balancingopts_} -- save any global commodity styles
|
& journalAddFile (f, txt) -- save the main file's info
|
||||||
& journalAddFile (f, txt) -- save the main file's info
|
& journalReverse -- convert all lists to the order they were parsed
|
||||||
& journalSetLastReadTime t -- save the last read time
|
pj3 <- pj2{jglobalcommoditystyles=fromMaybe mempty $ commodity_styles_ balancingopts_}
|
||||||
& journalReverse -- convert all lists to the order they were parsed
|
& journalApplyCommodityStyles -- Infer and apply commodity styles - should be done early
|
||||||
where
|
j <- pj3
|
||||||
checkAddAndBalance d j = do
|
& journalPostingsAddAccountTags -- Add account tags to postings' tags
|
||||||
newj <- j
|
& journalAddForecast (forecastPeriod iopts pj3) -- Add forecast transactions if enabled
|
||||||
-- Add account tags to postings' tags
|
& journalPostingsAddAccountTags -- Add account tags again to affect forecast transactions -- PERF: just to the new transactions ?
|
||||||
& journalPostingsAddAccountTags
|
& (if auto_ && not (null $ jtxnmodifiers pj3) then journalAddAutoPostings _ioDay balancingopts_ else pure) -- Add auto postings if enabled
|
||||||
-- Add forecast transactions if enabled
|
>>= Right . journalPostingsAddAccountTags -- Add account tags again to affect auto postings -- PERF: just to the new postings ?
|
||||||
& journalAddForecast (forecastPeriod iopts j)
|
>>= journalBalanceTransactions balancingopts_ -- Balance all transactions and maybe check balance assertions.
|
||||||
-- Add account tags again to affect forecast transactions -- PERF: just to the new transactions ?
|
<&> (if infer_equity_ then journalAddInferredEquityPostings else id) -- Add inferred equity postings, after balancing transactions and generating auto postings
|
||||||
& journalPostingsAddAccountTags
|
<&> journalInferMarketPricesFromTransactions -- infer market prices from commodity-exchanging transactions
|
||||||
-- Add auto postings if enabled
|
when strict_ $ do
|
||||||
& (if auto_ && not (null $ jtxnmodifiers j) then journalAddAutoPostings d balancingopts_ else pure)
|
journalCheckAccountsDeclared j -- If in strict mode, check all postings are to declared accounts
|
||||||
-- Add account tags again to affect auto postings -- PERF: just to the new postings ?
|
journalCheckCommoditiesDeclared j -- and using declared commodities
|
||||||
>>= Right . journalPostingsAddAccountTags
|
return j
|
||||||
-- Balance all transactions and maybe check balance assertions.
|
|
||||||
>>= journalBalanceTransactions balancingopts_
|
|
||||||
-- Add inferred equity postings, after balancing transactions and generating auto postings
|
|
||||||
<&> (if infer_equity_ then journalAddInferredEquityPostings else id)
|
|
||||||
-- infer market prices from commodity-exchanging transactions
|
|
||||||
<&> journalInferMarketPricesFromTransactions
|
|
||||||
|
|
||||||
when strict_ $ do
|
|
||||||
-- If in strict mode, check all postings are to declared accounts
|
|
||||||
journalCheckAccountsDeclared newj
|
|
||||||
-- and using declared commodities
|
|
||||||
journalCheckCommoditiesDeclared newj
|
|
||||||
|
|
||||||
return newj
|
|
||||||
|
|
||||||
-- | To all postings in the journal, add any tags from their account
|
-- | To all postings in the journal, add any tags from their account
|
||||||
-- (including those inherited from parent accounts).
|
-- (including those inherited from parent accounts).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user