Skip to content

Commit

Permalink
imp:commodities: also list commodities mentioned in P directives [#2280]
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Nov 3, 2024
1 parent a58948c commit 090f001
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hledger-lib/Hledger/Data/Journal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 090f001

Please sign in to comment.