From 29ee0c331f7468970ddb44cf50f027b39a9f7056 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Tue, 7 Dec 2021 11:40:32 +1100 Subject: [PATCH] imp: csv: Ignore --row-totals with tidy csv output. --- hledger/Hledger/Cli/Commands/Balance.hs | 9 +++++++-- hledger/test/balance/layout.test | 20 -------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index e8685262e..44c246c73 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -520,8 +520,13 @@ renderComponent topaligned oneline opts (acctname, depth, total) (FormatField lj -- The CSV will always include the initial headings row, -- and will include the final totals row unless --no-total is set. multiBalanceReportAsCsv :: ReportOpts -> MultiBalanceReport -> CSV -multiBalanceReportAsCsv opts@ReportOpts{..} = - (if transpose_ then transpose else id) . uncurry (++) . multiBalanceReportAsCsv' opts +multiBalanceReportAsCsv opts@ReportOpts{..} report = maybeTranspose allRows + where + allRows = case layout_ of + LayoutTidy -> rows -- tidy csv should not include totals or averages + _ -> rows ++ totals + (rows, totals) = multiBalanceReportAsCsv' opts report + maybeTranspose = if transpose_ then transpose else id multiBalanceReportAsCsv' :: ReportOpts -> MultiBalanceReport -> (CSV, CSV) multiBalanceReportAsCsv' opts@ReportOpts{..} (PeriodicReport colspans items tr) = diff --git a/hledger/test/balance/layout.test b/hledger/test/balance/layout.test index ab951e234..f39c22620 100644 --- a/hledger/test/balance/layout.test +++ b/hledger/test/balance/layout.test @@ -255,21 +255,6 @@ $ hledger -f bcexample.hledger bal -T -Y assets.*etrade -3 -O csv --layout=tidy "Assets:US:ETrade","2014","2014-01-01","2014-12-31","USD","4881.44" "Assets:US:ETrade","2014","2014-01-01","2014-12-31","VEA","14.00" "Assets:US:ETrade","2014","2014-01-01","2014-12-31","VHT","170.00" -"total","2012","2012-01-01","2012-12-31","GLD","0" -"total","2012","2012-01-01","2012-12-31","ITOT","10.00" -"total","2012","2012-01-01","2012-12-31","USD","337.18" -"total","2012","2012-01-01","2012-12-31","VEA","12.00" -"total","2012","2012-01-01","2012-12-31","VHT","106.00" -"total","2013","2013-01-01","2013-12-31","GLD","70.00" -"total","2013","2013-01-01","2013-12-31","ITOT","18.00" -"total","2013","2013-01-01","2013-12-31","USD","-98.12" -"total","2013","2013-01-01","2013-12-31","VEA","10.00" -"total","2013","2013-01-01","2013-12-31","VHT","18.00" -"total","2014","2014-01-01","2014-12-31","GLD","0" -"total","2014","2014-01-01","2014-12-31","ITOT","-11.00" -"total","2014","2014-01-01","2014-12-31","USD","4881.44" -"total","2014","2014-01-01","2014-12-31","VEA","14.00" -"total","2014","2014-01-01","2014-12-31","VHT","170.00" >=0 # 14. Single column balance report csv output with --layout=tidy @@ -281,9 +266,4 @@ $ 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","USD","5120.50" "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" -"total","2012-01-01..2014-10-11","2012-01-01","2014-10-11","GLD","70.00" -"total","2012-01-01..2014-10-11","2012-01-01","2014-10-11","ITOT","17.00" -"total","2012-01-01..2014-10-11","2012-01-01","2014-10-11","USD","5120.50" -"total","2012-01-01..2014-10-11","2012-01-01","2014-10-11","VEA","36.00" -"total","2012-01-01..2014-10-11","2012-01-01","2014-10-11","VHT","294.00" >=0