From 2a4170dd3b99a1c5130e943aef872c1233df9da7 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 4 Feb 2021 07:58:09 -0800 Subject: [PATCH] ui: transaction: show all decimal places (like print, cf #931) On the accounts screen and register screen we round amounts according to commodity styles, but when you drill down to a transaction you probably want to see the unrounded amounts. --- hledger-lib/Hledger/Data/Transaction.hs | 4 ++++ hledger-ui/Hledger/UI/TransactionScreen.hs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 5ffa9c44e..222f4e6c7 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -37,6 +37,7 @@ module Hledger.Data.Transaction ( transactionToCost, transactionApplyAliases, transactionMapPostings, + transactionMapPostingAmounts, -- nonzerobalanceerror, -- * date operations transactionDate2, @@ -623,6 +624,9 @@ transactionMapPostings :: (Posting -> Posting) -> Transaction -> Transaction transactionMapPostings f t@Transaction{tpostings=ps} = t{tpostings=map f ps} -- | Apply a transformation to a transaction's posting amounts. +transactionMapPostingAmounts :: (Amount -> Amount) -> Transaction -> Transaction +transactionMapPostingAmounts f = transactionMapPostings (postingTransformAmount (mapMixedAmount f)) + -- tests tests_Transaction :: TestTree diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index 889043cf3..c437e95d4 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -60,7 +60,7 @@ tsInit _ _ _ = error "init function called with wrong screen type, should not ha tsDraw :: UIState -> [Widget Name] tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts=ropts}}} ,ajournal=j - ,aScreen=TransactionScreen{tsTransaction=(i,t) + ,aScreen=TransactionScreen{tsTransaction=(i,t') ,tsTransactions=nts ,tsAccount=acct } @@ -71,6 +71,8 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{ -- Minibuffer e -> [minibuffer e, maincontent] _ -> [maincontent] where + -- as with print, show amounts with all of their decimal places + t = transactionMapPostingAmounts setFullPrecision t' maincontent = Widget Greedy Greedy $ do let prices = journalPriceOracle (infer_value_ ropts) j