From 090f001eee71435cb9658ab1fba21cceacfca9b6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 2 Nov 2024 16:48:08 -1000 Subject: [PATCH] imp:commodities: also list commodities mentioned in P directives [#2280] --- hledger-lib/Hledger/Data/Journal.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index ab6e3a472..588c8bd52 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -406,9 +406,13 @@ showJournalAmountsDebug = show.map showMixedAmountOneLine.journalPostingAmounts journalCommoditiesDeclared :: Journal -> [CommoditySymbol] journalCommoditiesDeclared = M.keys . jdeclaredcommodities --- | Sorted unique commodity symbols declared or inferred from this journal. +-- | Sorted unique commodity symbols mentioned in this journal. journalCommodities :: Journal -> S.Set CommoditySymbol -journalCommodities j = M.keysSet (jdeclaredcommodities j) <> M.keysSet (jinferredcommoditystyles j) +journalCommodities j = + M.keysSet (jdeclaredcommodities j) + <> M.keysSet (jinferredcommoditystyles j) + <> S.fromList (concatMap pdcommodities $ jpricedirectives j) + where pdcommodities pd = [pdcommodity pd, acommodity $ pdamount pd] -- | Unique transaction descriptions used in this journal. journalDescriptions :: Journal -> [Text] @@ -901,8 +905,7 @@ journalCommodityStylesWith :: Rounding -> Journal -> M.Map CommoditySymbol Amoun journalCommodityStylesWith r = amountStylesSetRounding r . journalCommodityStyles -- | Collect and save inferred amount styles for each commodity based on --- the posting amounts in that commodity (excluding price amounts), ie: --- "the format of the first amount, adjusted to the highest precision of all amounts". +-- the posting amounts in that commodity (excluding price amounts). -- Can return an error message eg if inconsistent number formats are found. journalInferCommodityStyles :: Journal -> Either String Journal journalInferCommodityStyles j =