;lib: move transactionNote/Payee to Transaction.hs
This commit is contained in:
parent
e6b709cb01
commit
6b61d1e0f1
@ -54,10 +54,6 @@ module Hledger.Data.Posting (
|
||||
concatAccountNames,
|
||||
accountNameApplyAliases,
|
||||
accountNameApplyAliasesMemo,
|
||||
-- * transaction description operations
|
||||
transactionPayee,
|
||||
transactionNote,
|
||||
payeeAndNoteFromDescription,
|
||||
-- * arithmetic
|
||||
sumPostings,
|
||||
-- * rendering
|
||||
@ -233,23 +229,6 @@ postingStatus Posting{pstatus=s, ptransaction=mt}
|
||||
Nothing -> Unmarked
|
||||
| otherwise = s
|
||||
|
||||
transactionPayee :: Transaction -> Text
|
||||
transactionPayee = fst . payeeAndNoteFromDescription . tdescription
|
||||
|
||||
transactionNote :: Transaction -> Text
|
||||
transactionNote = snd . payeeAndNoteFromDescription . tdescription
|
||||
|
||||
-- | Parse a transaction's description into payee and note (aka narration) fields,
|
||||
-- assuming a convention of separating these with | (like Beancount).
|
||||
-- Ie, everything up to the first | is the payee, everything after it is the note.
|
||||
-- When there's no |, payee == note == description.
|
||||
payeeAndNoteFromDescription :: Text -> (Text,Text)
|
||||
payeeAndNoteFromDescription t
|
||||
| T.null n = (t, t)
|
||||
| otherwise = (textstrip p, textstrip $ T.drop 1 n)
|
||||
where
|
||||
(p, n) = T.span (/= '|') t
|
||||
|
||||
-- | Tags for this posting including any inherited from its parent transaction.
|
||||
postingAllTags :: Posting -> [Tag]
|
||||
postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p)
|
||||
|
||||
@ -35,6 +35,10 @@ module Hledger.Data.Transaction (
|
||||
transactionDate2,
|
||||
-- * arithmetic
|
||||
transactionPostingBalances,
|
||||
-- * transaction description parts
|
||||
transactionPayee,
|
||||
transactionNote,
|
||||
-- payeeAndNoteFromDescription,
|
||||
-- * rendering
|
||||
showTransaction,
|
||||
showTransactionUnelided,
|
||||
@ -100,6 +104,23 @@ nulltransaction = Transaction {
|
||||
transaction :: String -> [Posting] -> Transaction
|
||||
transaction datestr ps = txnTieKnot $ nulltransaction{tdate=parsedate datestr, tpostings=ps}
|
||||
|
||||
transactionPayee :: Transaction -> Text
|
||||
transactionPayee = fst . payeeAndNoteFromDescription . tdescription
|
||||
|
||||
transactionNote :: Transaction -> Text
|
||||
transactionNote = snd . payeeAndNoteFromDescription . tdescription
|
||||
|
||||
-- | Parse a transaction's description into payee and note (aka narration) fields,
|
||||
-- assuming a convention of separating these with | (like Beancount).
|
||||
-- Ie, everything up to the first | is the payee, everything after it is the note.
|
||||
-- When there's no |, payee == note == description.
|
||||
payeeAndNoteFromDescription :: Text -> (Text,Text)
|
||||
payeeAndNoteFromDescription t
|
||||
| T.null n = (t, t)
|
||||
| otherwise = (textstrip p, textstrip $ T.drop 1 n)
|
||||
where
|
||||
(p, n) = T.span (/= '|') t
|
||||
|
||||
{-|
|
||||
Render a journal transaction as text in the style of Ledger's print command.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user