diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index cf380a170..e839954dc 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -14,6 +14,7 @@ tags. {-# LANGUAGE Rank2Types #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} module Hledger.Data.Transaction ( -- * Transaction nulltransaction, @@ -55,6 +56,7 @@ module Hledger.Data.Transaction ( sourceFirstLine, showGenericSourcePos, annotateErrorWithTransaction, + transactionFile, -- * tests tests_Transaction ) @@ -628,6 +630,13 @@ transactionMapPostings f t@Transaction{tpostings=ps} = t{tpostings=map f ps} transactionMapPostingAmounts :: (Amount -> Amount) -> Transaction -> Transaction transactionMapPostingAmounts f = transactionMapPostings (postingTransformAmount (mapMixedAmount f)) +-- | The file path from which this transaction was parsed. +transactionFile :: Transaction -> FilePath +transactionFile Transaction{tsourcepos} = + case tsourcepos of + GenericSourcePos f _ _ -> f + JournalSourcePos f _ -> f + -- tests tests_Transaction :: TestTree