Journal: make reordering optional in journalFinalise

Currently `journalFinalise` always reverses the order of
entries. However, if there are automated transactions, we might need
to run it twice. This adds a boolean flag to make reordering
optional. This will be used in the `parseAndFinaliseJournal`
functions.
This commit is contained in:
Jesse Rosenthal 2018-10-11 12:35:18 -04:00 committed by Simon Michael
parent c53502e1ac
commit b346d7f701

View File

@ -523,19 +523,21 @@ filterJournalTransactionsByAccount apats j@Journal{jtxns=ts} = j{jtxns=filter tm
-- use. Reverse parsed data to normal order, standardise amount -- use. Reverse parsed data to normal order, standardise amount
-- formats, check/ensure that transactions are balanced, and maybe -- formats, check/ensure that transactions are balanced, and maybe
-- check balance assertions. -- check balance assertions.
journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> ParsedJournal -> Either String Journal journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> Bool -> ParsedJournal -> Either String Journal
journalFinalise t path txt assrt j@Journal{jfiles=fs} = journalFinalise t path txt reorder assrt j@Journal{jfiles=fs} =
journalTieTransactions <$> let j' = if reorder
(journalBalanceTransactions assrt $ then j {jfiles = (path,txt) : reverse fs
journalApplyCommodityStyles $ ,jlastreadtime = t
j {jfiles = (path,txt) : reverse fs ,jdeclaredaccounts = reverse $ jdeclaredaccounts j
,jlastreadtime = t ,jtxns = reverse $ jtxns j -- NOTE: see addTransaction
,jdeclaredaccounts = reverse $ jdeclaredaccounts j ,jtxnmodifiers = reverse $ jtxnmodifiers j -- NOTE: see addTransactionModifier
,jtxns = reverse $ jtxns j -- NOTE: see addTransaction ,jperiodictxns = reverse $ jperiodictxns j -- NOTE: see addPeriodicTransaction
,jtxnmodifiers = reverse $ jtxnmodifiers j -- NOTE: see addTransactionModifier ,jmarketprices = reverse $ jmarketprices j -- NOTE: see addMarketPrice
,jperiodictxns = reverse $ jperiodictxns j -- NOTE: see addPeriodicTransaction }
,jmarketprices = reverse $ jmarketprices j -- NOTE: see addMarketPrice else j
}) in journalTieTransactions <$>
(journalBalanceTransactions assrt $ journalApplyCommodityStyles j')
journalNumberAndTieTransactions = journalTieTransactions . journalNumberTransactions journalNumberAndTieTransactions = journalTieTransactions . journalNumberTransactions