Add abs implementation for MixedAmount

This commit is contained in:
Michael Rees 2024-07-23 08:27:04 -05:00 committed by Simon Michael
parent 52253c01f6
commit e34fa491af
2 changed files with 3 additions and 4 deletions

View File

@ -764,7 +764,7 @@ instance Num MixedAmount where
negate = maNegate negate = maNegate
(+) = maPlus (+) = maPlus
(*) = error "error, mixed amounts do not support multiplication" -- PARTIAL: (*) = 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" signum = error "error, mixed amounts do not support signum"
-- | Calculate the key used to store an Amount within a MixedAmount. -- | Calculate the key used to store an Amount within a MixedAmount.

View File

@ -129,14 +129,13 @@ comparePostings ropts (ex:es) (a, pa) (b, pb) =
description = fmap (\t -> tdescription t) tx description = fmap (\t -> tdescription t) tx
-- If there's no transaction attached, then use empty text for the description -- If there's no transaction attached, then use empty text for the description
in fromMaybe "" description in fromMaybe "" description
absamount = mapMixedAmount (\amt -> amt { aquantity = abs (aquantity amt)})
comparison = case ex of 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) Amount' False -> compare (pamount a) (pamount b)
Account' False -> compare (paccount a) (paccount b) Account' False -> compare (paccount a) (paccount b)
Date' False -> compare (postingDateOrDate2 (whichDate ropts) a) (postingDateOrDate2 (whichDate ropts) b) Date' False -> compare (postingDateOrDate2 (whichDate ropts) a) (postingDateOrDate2 (whichDate ropts) b)
Description' False -> compare (getDescription a) (getDescription 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)) Amount' True -> compare (Down (pamount a)) (Down (pamount b))
Account' True -> compare (Down (paccount a)) (Down (paccount b)) Account' True -> compare (Down (paccount a)) (Down (paccount b))
Date' True -> compare (Down (postingDateOrDate2 (whichDate ropts) a)) (Down (postingDateOrDate2 (whichDate ropts) b)) Date' True -> compare (Down (postingDateOrDate2 (whichDate ropts) a)) (Down (postingDateOrDate2 (whichDate ropts) b))