From e34fa491af88173e96b1e7948858821f8fa1d2ad Mon Sep 17 00:00:00 2001 From: Michael Rees Date: Tue, 23 Jul 2024 08:27:04 -0500 Subject: [PATCH] Add abs implementation for MixedAmount --- hledger-lib/Hledger/Data/Amount.hs | 2 +- hledger-lib/Hledger/Reports/PostingsReport.hs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index aa61d9898..3f8a5e2eb 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -764,7 +764,7 @@ instance Num MixedAmount where negate = maNegate (+) = maPlus (*) = error "error, mixed amounts do not support multiplication" -- PARTIAL: - abs = error "error, mixed amounts do not support abs" + abs = mapMixedAmount (\amt -> amt { aquantity = abs (aquantity amt)}) signum = error "error, mixed amounts do not support signum" -- | Calculate the key used to store an Amount within a MixedAmount. diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index 7736495b4..41059088b 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -129,14 +129,13 @@ comparePostings ropts (ex:es) (a, pa) (b, pb) = description = fmap (\t -> tdescription t) tx -- If there's no transaction attached, then use empty text for the description in fromMaybe "" description - absamount = mapMixedAmount (\amt -> amt { aquantity = abs (aquantity amt)}) comparison = case ex of - AbsAmount' False -> compare (absamount (pamount a)) (absamount (pamount b)) + AbsAmount' False -> compare (abs (pamount a)) (abs (pamount b)) Amount' False -> compare (pamount a) (pamount b) Account' False -> compare (paccount a) (paccount b) Date' False -> compare (postingDateOrDate2 (whichDate ropts) a) (postingDateOrDate2 (whichDate ropts) b) Description' False -> compare (getDescription a) (getDescription b) - AbsAmount' True -> compare (Down (absamount (pamount a))) (Down (absamount (pamount b))) + AbsAmount' True -> compare (Down (abs (pamount a))) (Down (abs (pamount b))) Amount' True -> compare (Down (pamount a)) (Down (pamount b)) Account' True -> compare (Down (paccount a)) (Down (paccount b)) Date' True -> compare (Down (postingDateOrDate2 (whichDate ropts) a)) (Down (postingDateOrDate2 (whichDate ropts) b))