From 0dca0911f387707d48ea0b2017df17811ad77cba Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 29 Jan 2025 09:41:51 -1000 Subject: [PATCH] lib: negatePostingAmount -> postingNegateMainAmount --- hledger-lib/Hledger/Data/Posting.hs | 10 +++++----- .../Hledger/Reports/AccountTransactionsReport.hs | 2 +- hledger-lib/Hledger/Reports/PostingsReport.hs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 8968cc8be..03a47f878 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -63,7 +63,7 @@ module Hledger.Data.Posting ( -- * arithmetic sumPostings, - negatePostingAmount, + postingNegateMainAmount, -- * rendering showPosting, showPostingLines, @@ -381,9 +381,9 @@ accountNamesFromPostings = S.toList . S.fromList . map paccount sumPostings :: [Posting] -> MixedAmount sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt --- | Negate amount in a posting. -negatePostingAmount :: Posting -> Posting -negatePostingAmount = postingTransformAmount negate +-- | Negate the posting's main amount but not the balance assertion amount. +postingNegateMainAmount :: Posting -> Posting +postingNegateMainAmount p@Posting{pamount=a} = p{pamount=negate a} -- | Strip all prices from a Posting. postingStripCosts :: Posting -> Posting @@ -532,7 +532,7 @@ postingPriceDirectivesFromCost :: Posting -> [PriceDirective] postingPriceDirectivesFromCost p@Posting{pamount} = mapMaybe (amountPriceDirectiveFromCost $ postingDate p) $ amountsRaw pamount --- | Apply a transform function to this posting's amount. +-- | Apply a transform function to this posting's main amount (but not its balance assertion amount). postingTransformAmount :: (MixedAmount -> MixedAmount) -> Posting -> Posting postingTransformAmount f p@Posting{pamount=a} = p{pamount=f a} diff --git a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs index 4c4af9182..2c7f96929 100644 --- a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs +++ b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs @@ -162,7 +162,7 @@ accountTransactionsReport rspec@ReportSpec{_rsReportOpts=ropts} j thisacctq = it . traceAtWith 5 (("ts4:\n"++).pshowTransactions.map snd) . sortBy (comparing (Down . fst) <> comparing (Down . tindex . snd)) . map (\t -> (transactionRegisterDate wd reportq thisacctq t, t)) - . map (if invert_ ropts then (\t -> t{tpostings = map negatePostingAmount $ tpostings t}) else id) + . map (if invert_ ropts then (\t -> t{tpostings = map postingNegateMainAmount $ tpostings t}) else id) $ jtxns acctJournal pshowTransactions :: [Transaction] -> String diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index 146bf9e56..66b24744b 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -158,7 +158,7 @@ matchedPostingsBeforeAndDuring rspec@ReportSpec{_rsReportOpts=ropts,_rsQuery=q} beforestartq = dbg3 "beforestartq" $ dateqtype $ DateSpan Nothing (Exact <$> spanStart reportspan) beforeandduringps = sortOn (postingDateOrDate2 (whichDate ropts)) -- sort postings by date or date2 - . (if invert_ ropts then map negatePostingAmount else id) -- with --invert, invert amounts + . (if invert_ ropts then map postingNegateMainAmount else id) -- with --invert, invert amounts . journalPostings -- With most calls we will not require transaction prices past this point, and can get a big -- speed improvement by stripping them early. In some cases, such as in hledger-ui, we still