journal: split up the parts of journalFinalise, and use them as needed.
`journalFinalise` is only used in the `parseAndFinaliseJournal` functions, but it needs to be run differently at different stages when transaction modifiers are applied. This change breaks it into smaller functions, and uses those smaller parts in `parseAndFinaliseJournal` as needed.
This commit is contained in:
parent
20f134c96b
commit
53b3e2bd94
@ -22,6 +22,9 @@ module Hledger.Data.Journal (
|
||||
journalCommodityStyles,
|
||||
journalConvertAmountsToCost,
|
||||
journalFinalise,
|
||||
journalReverse,
|
||||
journalSetTime,
|
||||
journalSetFilePath,
|
||||
journalPivot,
|
||||
-- * Filtering
|
||||
filterJournalTransactions,
|
||||
@ -519,6 +522,23 @@ filterJournalTransactionsByAccount apats j@Journal{jtxns=ts} = j{jtxns=filter tm
|
||||
|
||||
-}
|
||||
|
||||
journalReverse :: Journal -> Journal
|
||||
journalReverse j =
|
||||
j {jfiles = reverse $ jfiles j
|
||||
,jdeclaredaccounts = reverse $ jdeclaredaccounts j
|
||||
,jtxns = reverse $ jtxns j
|
||||
,jtxnmodifiers = reverse $ jtxnmodifiers j
|
||||
,jperiodictxns = reverse $ jperiodictxns j
|
||||
,jmarketprices = reverse $ jmarketprices j
|
||||
}
|
||||
|
||||
journalSetTime :: ClockTime -> Journal -> Journal
|
||||
journalSetTime t j = j{ jlastreadtime = t }
|
||||
|
||||
journalSetFilePath :: FilePath -> Text -> Journal -> Journal
|
||||
journalSetFilePath path txt j = j {jfiles = (path,txt) : jfiles j}
|
||||
|
||||
|
||||
-- | Do post-parse processing on a parsed journal to make it ready for
|
||||
-- use. Reverse parsed data to normal order, standardise amount
|
||||
-- formats, check/ensure that transactions are balanced, and maybe
|
||||
|
||||
@ -293,13 +293,21 @@ parseAndFinaliseJournal' parser iopts f txt = do
|
||||
-- be false pending modifiers) and we don't reorder the second
|
||||
-- time. If we are only running once, we reorder and follow the
|
||||
-- options for checking assertions.
|
||||
let runFin :: Bool -> Bool -> (ParsedJournal -> Either String Journal)
|
||||
runFin reorder ignore = journalFinalise t f txt reorder ignore
|
||||
fj = if auto_ iopts && (not . null . jtxnmodifiers) pj
|
||||
let fj = if auto_ iopts && (not . null . jtxnmodifiers) pj
|
||||
then applyTransactionModifiers <$>
|
||||
runFin True False pj >>=
|
||||
runFin False (not $ ignore_assertions_ iopts)
|
||||
else runFin True (not $ ignore_assertions_ iopts) pj
|
||||
(journalBalanceTransactions False $
|
||||
journalReverse $
|
||||
journalApplyCommodityStyles pj) >>=
|
||||
(\j -> journalBalanceTransactions (not $ ignore_assertions_ iopts) $
|
||||
journalSetTime t $
|
||||
journalSetFilePath f txt $
|
||||
j)
|
||||
else journalBalanceTransactions (not $ ignore_assertions_ iopts) $
|
||||
journalReverse $
|
||||
journalApplyCommodityStyles $
|
||||
journalSetTime t $
|
||||
journalSetFilePath f txt $
|
||||
pj
|
||||
in
|
||||
case fj of
|
||||
Right j -> return j
|
||||
|
||||
Loading…
Reference in New Issue
Block a user