fix: layout: Commodity symbols should be omitted in --layout=bare when
all amounts are zero. (#1789)
This commit is contained in:
parent
55a022a941
commit
2a51b6e9a4
@ -259,7 +259,7 @@ module Hledger.Cli.Commands.Balance (
|
||||
) where
|
||||
|
||||
import Data.Default (def)
|
||||
import Data.List (transpose, foldl', transpose)
|
||||
import Data.List (transpose, transpose)
|
||||
import qualified Data.Set as S
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Text as T
|
||||
@ -456,7 +456,7 @@ balanceReportAsText' opts ((items, total)) =
|
||||
, Cell TopLeft (fmap wbFromText cs)
|
||||
, Cell TopLeft (replicate (length damts - 1) mempty ++ [wbFromText dispname]) ]
|
||||
where dopts = oneLine{displayColour=color_ opts, displayOrder=Just cs}
|
||||
cs = S.toList $ maCommodities amt
|
||||
cs = if mixedAmountLooksZero amt then [""] else S.toList $ maCommodities amt
|
||||
dispname = T.replicate ((depth - 1) * 2) " " <> acctname
|
||||
damts = showMixedAmountLinesB dopts amt
|
||||
lines = fmap render items
|
||||
@ -703,14 +703,14 @@ balanceReportAsTable opts@ReportOpts{average_, row_total_, balanceaccum_}
|
||||
multiBalanceRowAsWbs :: AmountDisplayOpts -> ReportOpts -> [DateSpan] -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
|
||||
multiBalanceRowAsWbs bopts ReportOpts{..} colspans (PeriodicReportRow _ as rowtot rowavg) =
|
||||
case layout_ of
|
||||
LayoutWide width -> [fmap (showMixedAmountB bopts{displayMaxWidth=width}) all]
|
||||
LayoutWide width -> [fmap (showMixedAmountB bopts{displayMaxWidth=width}) allamts]
|
||||
LayoutTall -> paddedTranspose mempty
|
||||
. fmap (showMixedAmountLinesB bopts{displayMaxWidth=Nothing})
|
||||
$ all
|
||||
$ allamts
|
||||
LayoutBare -> zipWith (:) (fmap wbFromText cs) -- add symbols
|
||||
. transpose -- each row becomes a list of Text quantities
|
||||
. fmap (showMixedAmountLinesB bopts{displayOrder=Just cs, displayMinWidth=Nothing})
|
||||
$ all
|
||||
$ allamts
|
||||
LayoutTidy -> concat
|
||||
. zipWith (map . addDateColumns) colspans
|
||||
. fmap ( zipWith (\c a -> [wbFromText c, a]) cs
|
||||
@ -719,10 +719,8 @@ multiBalanceRowAsWbs bopts ReportOpts{..} colspans (PeriodicReportRow _ as rowto
|
||||
-- complicates the data representation and can be easily calculated
|
||||
where
|
||||
totalscolumn = row_total_ && balanceaccum_ `notElem` [Cumulative, Historical]
|
||||
cs = S.toList . foldl' S.union mempty $ fmap maCommodities all
|
||||
all = as
|
||||
++ [rowtot | totalscolumn && not (null as)]
|
||||
++ [rowavg | average_ && not (null as)]
|
||||
cs = if all mixedAmountLooksZero allamts then [""] else S.toList $ foldMap maCommodities allamts
|
||||
allamts = as ++ [rowtot | totalscolumn && not (null as)] ++ [rowavg | average_ && not (null as)]
|
||||
addDateColumns span@(DateSpan s e) = (wbFromText (showDateSpan span) :)
|
||||
. (wbFromText (maybe "" showDate s) :)
|
||||
. (wbFromText (maybe "" (showDate . addDays (-1)) e) :)
|
||||
|
||||
@ -267,3 +267,28 @@ $ hledger -f bcexample.hledger bal -T assets.*etrade -3 -O csv --layout=tidy
|
||||
"Assets:US:ETrade","2012-01-01..2014-10-11","2012-01-01","2014-10-11","VEA","36.00"
|
||||
"Assets:US:ETrade","2012-01-01..2014-10-11","2012-01-01","2014-10-11","VHT","294.00"
|
||||
>=0
|
||||
|
||||
<
|
||||
2021-01-01 Test
|
||||
Assets:Bank INR 1.00
|
||||
Equity:Opening INR -1.00
|
||||
|
||||
# 15. Should omit commodity from totals row when the sum is zero with --layout=bare. (#1789)
|
||||
$ hledger -f - bal --layout=bare
|
||||
1.00 INR Assets:Bank
|
||||
-1.00 INR Equity:Opening
|
||||
-----
|
||||
0
|
||||
>=0
|
||||
|
||||
# 16. The same with -M. (#1789)
|
||||
$ hledger -f - bal --layout=bare -M
|
||||
Balance changes in 2021-01:
|
||||
|
||||
|| Commodity Jan
|
||||
================++==================
|
||||
Assets:Bank || INR 1.00
|
||||
Equity:Opening || INR -1.00
|
||||
----------------++------------------
|
||||
|| 0
|
||||
>=0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user