;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,
|
concatAccountNames,
|
||||||
accountNameApplyAliases,
|
accountNameApplyAliases,
|
||||||
accountNameApplyAliasesMemo,
|
accountNameApplyAliasesMemo,
|
||||||
-- * transaction description operations
|
|
||||||
transactionPayee,
|
|
||||||
transactionNote,
|
|
||||||
payeeAndNoteFromDescription,
|
|
||||||
-- * arithmetic
|
-- * arithmetic
|
||||||
sumPostings,
|
sumPostings,
|
||||||
-- * rendering
|
-- * rendering
|
||||||
@ -233,23 +229,6 @@ postingStatus Posting{pstatus=s, ptransaction=mt}
|
|||||||
Nothing -> Unmarked
|
Nothing -> Unmarked
|
||||||
| otherwise = s
|
| 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.
|
-- | Tags for this posting including any inherited from its parent transaction.
|
||||||
postingAllTags :: Posting -> [Tag]
|
postingAllTags :: Posting -> [Tag]
|
||||||
postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p)
|
postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p)
|
||||||
|
|||||||
@ -35,6 +35,10 @@ module Hledger.Data.Transaction (
|
|||||||
transactionDate2,
|
transactionDate2,
|
||||||
-- * arithmetic
|
-- * arithmetic
|
||||||
transactionPostingBalances,
|
transactionPostingBalances,
|
||||||
|
-- * transaction description parts
|
||||||
|
transactionPayee,
|
||||||
|
transactionNote,
|
||||||
|
-- payeeAndNoteFromDescription,
|
||||||
-- * rendering
|
-- * rendering
|
||||||
showTransaction,
|
showTransaction,
|
||||||
showTransactionUnelided,
|
showTransactionUnelided,
|
||||||
@ -100,6 +104,23 @@ nulltransaction = Transaction {
|
|||||||
transaction :: String -> [Posting] -> Transaction
|
transaction :: String -> [Posting] -> Transaction
|
||||||
transaction datestr ps = txnTieKnot $ nulltransaction{tdate=parsedate datestr, tpostings=ps}
|
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.
|
Render a journal transaction as text in the style of Ledger's print command.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user