From 228fc9eb3cbcc9bdd3446322bd373f1c2ab956bc Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 15 Jan 2019 06:14:47 -0800 Subject: [PATCH] preserve correct file order when using --auto (fixes #949) And clarify parseAndFinaliseJournal a bit. --- hledger-lib/Hledger/Read/Common.hs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 31a949bc9..e9cb7517e 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -264,14 +264,23 @@ parseAndFinaliseJournal parser iopts f txt = do -- time. If we are only running once, we reorder and follow -- the options for checking assertions. let fj = if auto_ iopts && (not . null . jtxnmodifiers) pj - then applyTransactionModifiers <$> - (journalBalanceTransactions False $ - journalReverse $ - journalApplyCommodityStyles pj) >>= - (\j -> journalBalanceTransactions (not $ ignore_assertions_ iopts) $ - journalAddFile (f, txt) $ - journalSetLastReadTime t $ - j) + + -- with transaction modifiers + then + -- first pass + applyTransactionModifiers <$> + (journalBalanceTransactions False $ + -- journalReverse $ -- can skip this one + journalApplyCommodityStyles pj) + -- second pass + >>= (\j -> + journalBalanceTransactions (not $ ignore_assertions_ iopts) $ + journalReverse $ + journalAddFile (f, txt) $ + journalSetLastReadTime t $ + j) + + -- without transaction modifiers else journalBalanceTransactions (not $ ignore_assertions_ iopts) $ journalReverse $ journalAddFile (f, txt) $