From 80b34ea48d1eab300e1d06544691fd98161c99cd Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 13 Nov 2018 11:18:08 -0800 Subject: [PATCH] lib: TransactionModifier: cleanup --- .../Hledger/Data/TransactionModifier.hs | 35 ++++--------------- hledger-lib/Hledger/Data/Types.hs | 2 +- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/hledger-lib/Hledger/Data/TransactionModifier.hs b/hledger-lib/Hledger/Data/TransactionModifier.hs index 90952088b..6a2a33d5b 100644 --- a/hledger-lib/Hledger/Data/TransactionModifier.hs +++ b/hledger-lib/Hledger/Data/TransactionModifier.hs @@ -76,35 +76,6 @@ transactionModifierToFunction mt = tmParseQuery :: TransactionModifier -> (Day -> Query) tmParseQuery mt = fst . flip parseQuery (tmquerytxt mt) ----- | 'DateSpan' of all dates mentioned in 'Journal' ----- ----- >>> jdatespan nulljournal ----- DateSpan - ----- >>> jdatespan nulljournal{jtxns=[nulltransaction{tdate=read "2016-01-01"}] } ----- DateSpan 2016/01/01 ----- >>> jdatespan nulljournal{jtxns=[nulltransaction{tdate=read "2016-01-01", tpostings=[nullposting{pdate=Just $ read "2016-02-01"}]}] } ----- DateSpan 2016/01/01-2016/02/01 ---jdatespan :: Journal -> DateSpan ---jdatespan j --- | null dates = nulldatespan --- | otherwise = DateSpan (Just $ minimum dates) (Just $ 1 `addDays` maximum dates) --- where --- dates = concatMap tdates $ jtxns j - ----- | 'DateSpan' of all dates mentioned in 'Transaction' ----- ----- >>> tdates nulltransaction ----- [0000-01-01] ---tdates :: Transaction -> [Day] ---tdates t = tdate t : concatMap pdates (tpostings t) ++ maybeToList (tdate2 t) where --- pdates p = catMaybes [pdate p, pdate2 p] - -postingScale :: Posting -> Maybe Quantity -postingScale p = - case amounts $ pamount p of - [a] | amultiplier a -> Just $ aquantity a - _ -> Nothing - -- | Converts a 'TransactionModifier''s posting to a 'Posting'-generating function, -- which will be used to make a new posting based on the old one (an "automated posting"). tmPostingToFunction :: Posting -> (Posting -> Posting) @@ -122,6 +93,12 @@ tmPostingToFunction p' = "" -> Mixed as c -> Mixed [a{acommodity = c, astyle = astyle amount, aprice = aprice amount} | a <- as] +postingScale :: Posting -> Maybe Quantity +postingScale p = + case amounts $ pamount p of + [a] | amultiplier a -> Just $ aquantity a + _ -> Nothing + renderPostingCommentDates :: Posting -> Posting renderPostingCommentDates p = p { pcomment = comment' } where diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index 84424dd8b..132b882e7 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -205,7 +205,7 @@ data Amount = Amount { aquantity :: Quantity, aprice :: Price, -- ^ the (fixed) price for this amount, if any astyle :: AmountStyle, - amultiplier :: Bool -- ^ amount is a multipier used in TransactionModifier postings + amultiplier :: Bool -- ^ kludge: a flag marking this amount and posting as a multipier in a TransactionModifier } deriving (Eq,Ord,Typeable,Data,Generic,Show) instance NFData Amount