diff --git a/hledger-lib/Hledger/Data/AccountName.hs b/hledger-lib/Hledger/Data/AccountName.hs index c11fa0c6c..d953ad9b9 100644 --- a/hledger-lib/Hledger/Data/AccountName.hs +++ b/hledger-lib/Hledger/Data/AccountName.hs @@ -56,9 +56,11 @@ accountNameLevel a = T.length (T.filter (==acctsepchar) a) + 1 accountNameDrop :: Int -> AccountName -> AccountName accountNameDrop n = accountNameFromComponents . drop n . accountNameComponents --- | ["a:b:c","d:e"] -> ["a","a:b","a:b:c","d","d:e"] +-- | Sorted unique account names implied by these account names, +-- ie these plus all their parent accounts up to the root. +-- Eg: ["a:b:c","d:e"] -> ["a","a:b","a:b:c","d","d:e"] expandAccountNames :: [AccountName] -> [AccountName] -expandAccountNames as = nub $ concatMap expandAccountName as +expandAccountNames as = nub $ sort $ concatMap expandAccountName as -- | "a:b:c" -> ["a","a:b","a:b:c"] expandAccountName :: AccountName -> [AccountName] diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index f6456347f..cee6dee8a 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -132,8 +132,9 @@ hasAmount = (/= missingmixedamt) . pamount isAssignment :: Posting -> Bool isAssignment p = not (hasAmount p) && isJust (pbalanceassertion p) +-- | Sorted unique account names referenced by these postings. accountNamesFromPostings :: [Posting] -> [AccountName] -accountNamesFromPostings = nub . map paccount +accountNamesFromPostings = nub . sort . map paccount sumPostings :: [Posting] -> MixedAmount sumPostings = sumStrict . map pamount