diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 28d8be8d3..9b67b9aa0 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -22,6 +22,7 @@ module Hledger.Data.Journal ( addPeriodicTransaction, addTransaction, journalInferMarketPricesFromTransactions, + journalInferCommodityStyles, journalApplyCommodityStyles, commodityStylesFromAmounts, journalCommodityStyles, diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 832f87a83..994743a48 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -332,7 +332,9 @@ journalFinalise iopts@InputOpts{..} f txt pj = do -- >>= Right . dbg0With (concatMap (T.unpack.showTransaction).jtxns) -- >>= \j -> deepseq (concatMap (T.unpack.showTransaction).jtxns $ j) (return j) >>= journalMarkRedundantCosts -- Mark redundant costs, to help journalBalanceTransactions ignore them - >>= journalBalanceTransactions balancingopts_ -- Balance all transactions and maybe check balance assertions. + >>= journalBalanceTransactions balancingopts_ -- infer balance assignments and missing amounts and maybe check balance assertions. + >>= journalInferCommodityStyles -- infer commodity styles once more now that all posting amounts are present (XXX or journalApplyCommodityStyles ?) + -- >>= Right . dbg0With (pshow.journalCommodityStyles) >>= (if infer_costs_ then journalInferCostsFromEquity else pure) -- Maybe infer costs from equity postings where possible <&> (if infer_equity_ then journalInferEquityFromCosts verbose_tags_ else id) -- Maybe infer equity postings from costs where possible <&> journalInferMarketPricesFromTransactions -- infer market prices from commodity-exchanging transactions diff --git a/hledger/test/journal/precision.test b/hledger/test/journal/precision.test index dfac0a04a..843cf5380 100644 --- a/hledger/test/journal/precision.test +++ b/hledger/test/journal/precision.test @@ -121,7 +121,7 @@ $ hledger -f- print --explicit >= 0 -## 8. Here the price should be displayed with precision 7 +# 8. Here the price should be displayed with precision 7 # (E's precision 4 + F's precision 3). < 2015/1/1 @@ -135,3 +135,13 @@ $ hledger -f- print --explicit f F -320.000 >= 0 + +# 9. Posting amounts inferred from balance assignments also affect commodity styles. (#2091) +< +2023-01-01 + (a) 1 A +2023-01-02 + (a) = 2.2 A +$ hledger -f- reg +2023-01-01 (a) 1.0 A 1.0 A +2023-01-02 (a) 1.2 A 2.2 A