imp!:aregister, journal: same-day txns respect order of -f options

If transactions on the same date are coming from two files specified
with -f options, we expect them to be displayed in parse order, ie
respecting the order of the -f options. This wasn't always the case,
now it is.

Also, transactions' tindex field is now unique across all files,
where previously it started at 1 in each file. This affects hledger
data generally, not just the aregister command.
This commit is contained in:
Simon Michael 2025-12-07 17:21:36 -10:00
parent 28f2180649
commit 67b2063809
2 changed files with 6 additions and 1 deletions

View File

@ -167,6 +167,7 @@ import Hledger.Utils
import Prelude hiding (getContents, writeFile)
import Hledger.Data.JournalChecks (journalStrictChecks)
import Text.Printf (printf)
import Hledger.Data.Journal (journalNumberTransactions)
--- ** doctest setup
-- $setup
@ -353,7 +354,10 @@ readJournalFiles iopts@InputOpts{strict_, new_, new_save_} prefixedfiles = do
readJournalFilesAndLatestDates :: InputOpts -> [PrefixedFilePath] -> ExceptT String IO (Journal, [LatestDatesForFile])
readJournalFilesAndLatestDates iopts pfs = do
(js, lastdates) <- unzip <$> mapM (readJournalFileAndLatestDates iopts) pfs
return (maybe def sconcat $ nonEmpty js, catMaybes lastdates)
-- Also renumber the concatenated transactions. In 1.51 and before, tindex restarted from 1 in each file.
-- Now we ensure tindex is unique across all files. This helps aregister preserve txns' parse order,
-- and with luck won't cause problems for anyone.
return (journalNumberTransactions $ maybe def sconcat $ nonEmpty js, catMaybes lastdates)
-- | An easy version of 'readJournal' which assumes default options, and fails in the IO monad.
readJournal' :: Handle -> IO Journal

View File

@ -46,6 +46,7 @@ Transactions in assets:checking and subaccounts (matching query):
# matching postings) then by parse order. (#1642)
# Also, make sure to use the posting date of matching transactions, if it
# differs from the transaction date.
# Also, parse order respects the order of -f options on command line (not tested here).
<
~ 2021-01-03 sixth, because forecast transactions come after normal transactions
(a) 6