From b346d7f701c067a4917d33eb7beaeea29b0dcc75 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 11 Oct 2018 12:35:18 -0400 Subject: [PATCH] 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. --- hledger-lib/Hledger/Data/Journal.hs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 40355b950..7fa18490a 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -523,19 +523,21 @@ filterJournalTransactionsByAccount apats j@Journal{jtxns=ts} = j{jtxns=filter tm -- use. Reverse parsed data to normal order, standardise amount -- formats, check/ensure that transactions are balanced, and maybe -- check balance assertions. -journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> ParsedJournal -> Either String Journal -journalFinalise t path txt assrt j@Journal{jfiles=fs} = - journalTieTransactions <$> - (journalBalanceTransactions assrt $ - journalApplyCommodityStyles $ - j {jfiles = (path,txt) : reverse fs - ,jlastreadtime = t - ,jdeclaredaccounts = reverse $ jdeclaredaccounts j - ,jtxns = reverse $ jtxns j -- NOTE: see addTransaction - ,jtxnmodifiers = reverse $ jtxnmodifiers j -- NOTE: see addTransactionModifier - ,jperiodictxns = reverse $ jperiodictxns j -- NOTE: see addPeriodicTransaction - ,jmarketprices = reverse $ jmarketprices j -- NOTE: see addMarketPrice - }) +journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> Bool -> ParsedJournal -> Either String Journal +journalFinalise t path txt reorder assrt j@Journal{jfiles=fs} = + let j' = if reorder + then j {jfiles = (path,txt) : reverse fs + ,jlastreadtime = t + ,jdeclaredaccounts = reverse $ jdeclaredaccounts j + ,jtxns = reverse $ jtxns j -- NOTE: see addTransaction + ,jtxnmodifiers = reverse $ jtxnmodifiers j -- NOTE: see addTransactionModifier + ,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