Skip to content

Commit

Permalink
imp: web: round amounts to display precision as before (precisiongeddon)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Nov 14, 2023
1 parent 6bd862e commit 5ee2139
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions hledger-lib/Hledger/Data/Amount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exchange rates.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}

module Hledger.Data.Amount (
-- * Commodity
Expand Down Expand Up @@ -1011,6 +1012,10 @@ mixedAmountSetStyles = styleAmounts
instance HasAmounts MixedAmount where
styleAmounts styles = mapMixedAmountUnsafe (styleAmounts styles)

instance HasAmounts Account where
styleAmounts styles acct@Account{aebalance,aibalance} =
acct{aebalance=styleAmounts styles aebalance, aibalance=styleAmounts styles aibalance}

-- | Reset each individual amount's display style to the default.
mixedAmountUnstyled :: MixedAmount -> MixedAmount
mixedAmountUnstyled = mapMixedAmountUnsafe amountUnstyled
Expand Down
1 change: 1 addition & 0 deletions hledger-web/Hledger/Web/Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ instance Yesod App where

let accounts =
balanceReportAsHtml (JournalR, RegisterR) here hideEmptyAccts j qparam qopts $
styleAmounts (journalCommodityStylesWith HardRounding j) $
balanceReport rspec' j

topShowmd = if showSidebar then "col-md-4" else "col-any-0" :: Text
Expand Down
4 changes: 3 additions & 1 deletion hledger-web/Hledger/Web/Handler/JournalR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ getJournalR = do
title' = title <> if q /= Any then ", filtered" else ""
acctlink a = (RegisterR, [("q", replaceInacct qparam $ accountQuery a)])
rspec = (reportspec_ $ cliopts_ opts){_rsQuery = filterQuery (not . queryIsDepth) q}
items = reverse $ entriesReport rspec j
items = reverse $
styleAmounts (journalCommodityStylesWith HardRounding j) $
entriesReport rspec j
transactionFrag = transactionFragment j

defaultLayout $ do
Expand Down
8 changes: 6 additions & 2 deletions hledger-web/Hledger/Web/Handler/MiscR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ getAccountsR = do
VD{j} <- getViewData
require ViewPermission
selectRep $ do
provideJson $ flattenAccounts $ mapAccounts (accountSetDeclarationInfo j) $ ledgerRootAccount $ ledgerFromJournal Any j
provideJson $
styleAmounts (journalCommodityStylesWith HardRounding j) $
flattenAccounts $ mapAccounts (accountSetDeclarationInfo j) $ ledgerRootAccount $ ledgerFromJournal Any j

getAccounttransactionsR :: Text -> Handler TypedContent
getAccounttransactionsR a = do
Expand All @@ -101,5 +103,7 @@ getAccounttransactionsR a = do
rspec = defreportspec
thisacctq = Acct $ accountNameToAccountRegex a -- includes subs
selectRep $ do
provideJson $ accountTransactionsReport rspec{_rsQuery=Any} j thisacctq
provideJson $
styleAmounts (journalCommodityStylesWith HardRounding j) $
accountTransactionsReport rspec{_rsQuery=Any} j thisacctq

4 changes: 3 additions & 1 deletion hledger-web/Hledger/Web/Handler/RegisterR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ getRegisterR = do
zip xs $
zip (map (T.unpack . accountSummarisedName . paccount) xs) $
tail $ (", "<$xs) ++ [""]
items = accountTransactionsReport rspec{_rsQuery=q} j acctQuery
items =
styleAmounts (journalCommodityStylesWith HardRounding j) $
accountTransactionsReport rspec{_rsQuery=q} j acctQuery
balancelabel
| isJust (inAccount qopts), balanceaccum_ (_rsReportOpts rspec) == Historical = "Historical Total"
| isJust (inAccount qopts) = "Period Total"
Expand Down

0 comments on commit 5ee2139

Please sign in to comment.