cli: Commands.Balance: hide total rows for all output formats for layout=tidy

This commit is contained in:
Henning Thielemann 2024-10-15 23:16:39 +02:00 committed by Simon Michael
parent fa58dc11f4
commit 270360a103

View File

@ -381,7 +381,7 @@ balancemode = hledgerCommandMode
-- | The balance command, prints a balance report. -- | The balance command, prints a balance report.
balance :: CliOpts -> Journal -> IO () balance :: CliOpts -> Journal -> IO ()
balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ of balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ ropts of
CalcBudget -> do -- single or multi period budget report CalcBudget -> do -- single or multi period budget report
let rspan = fst $ reportSpan j rspec let rspan = fst $ reportSpan j rspec
budgetreport = styleAmounts styles $ budgetReport rspec (balancingopts_ $ inputopts_ opts) rspan j budgetreport = styleAmounts styles $ budgetReport rspec (balancingopts_ $ inputopts_ opts) rspan j
@ -424,9 +424,14 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ of
writeOutputLazyText opts $ render report writeOutputLazyText opts $ render report
where where
styles = journalCommodityStylesWith HardRounding j styles = journalCommodityStylesWith HardRounding j
ropts@ReportOpts{..} = _rsReportOpts rspec ropts =
let ropts0 = _rsReportOpts rspec in
ropts0 {
-- tidy csv is defined externally and must not include totals or averages
no_total_ = no_total_ ropts0 || layout_ ropts0 == LayoutTidy
}
-- Tidy csv/tsv should be consistent between single period and multiperiod reports. -- Tidy csv/tsv should be consistent between single period and multiperiod reports.
multiperiod = interval_ /= NoInterval || (layout_ == LayoutTidy && delimited) multiperiod = interval_ ropts /= NoInterval || (layout_ ropts == LayoutTidy && delimited)
delimited = fmt == "csv" || fmt == "tsv" delimited = fmt == "csv" || fmt == "tsv"
fmt = outputFormatFromOpts opts fmt = outputFormatFromOpts opts
@ -748,17 +753,12 @@ amountType bopts amt =
-- The CSV will always include the initial headings row, -- The CSV will always include the initial headings row,
-- and will include the final totals row unless --no-total is set. -- and will include the final totals row unless --no-total is set.
multiBalanceReportAsCsv :: ReportOpts -> MultiBalanceReport -> CSV multiBalanceReportAsCsv :: ReportOpts -> MultiBalanceReport -> CSV
multiBalanceReportAsCsv opts@ReportOpts{..} report = maybeTranspose allRows multiBalanceReportAsCsv opts@ReportOpts{..} report =
(if transpose_ then transpose else id) $
rawTableContent $ header : body ++ totals
where where
allRows =
rawTableContent $
case layout_ of
LayoutTidy -> rows -- tidy csv should not include totals or averages
_ -> rows ++ totals
rows = header:body
(header, body, totals) = (header, body, totals) =
multiBalanceReportAsSpreadsheetParts machineFmt opts report multiBalanceReportAsSpreadsheetParts machineFmt opts report
maybeTranspose = if transpose_ then transpose else id
-- | Render the Spreadsheet table rows (CSV, ODS, HTML) for a MultiBalanceReport. -- | Render the Spreadsheet table rows (CSV, ODS, HTML) for a MultiBalanceReport.
-- Returns the heading row, 0 or more body rows, and the totals row if enabled. -- Returns the heading row, 0 or more body rows, and the totals row if enabled.