From d931e4919eb9cfad44b8c4d60a53ae89d97f63cb Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Thu, 4 Mar 2021 09:58:36 +1100 Subject: [PATCH] cli: Allow overriding with --periodic (rather than the old --change) and properly calculate requestedspan in CompoundBalanceReport. --- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 5 +- hledger/test/journal/valuechange.test | 51 ++++++++++++------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index e18663aed..e7c3dcf51 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -111,7 +111,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r parse = \case "historical" -> Just HistoricalBalance "cumulative" -> Just CumulativeChange - "change" -> Just PeriodChange + "periodic" -> Just PeriodChange _ -> Nothing balancetype = fromMaybe cbctype mBalanceTypeOverride -- Set balance type in the report options. @@ -135,8 +135,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r _ -> showDateSpan requestedspan where enddates = map (addDays (-1)) . mapMaybe spanEnd $ cbrDates cbr -- these spans will always have a definite end date - requestedspan = queryDateSpan date2_ (rsQuery rspec) - `spanDefaultsFrom` journalDateSpan date2_ j + requestedspan = reportSpan j rspec -- when user overrides, add an indication to the report title -- Do we need to deal with overridden ReportType? diff --git a/hledger/test/journal/valuechange.test b/hledger/test/journal/valuechange.test index 2c76dd2e5..cf21b89e2 100644 --- a/hledger/test/journal/valuechange.test +++ b/hledger/test/journal/valuechange.test @@ -7,16 +7,16 @@ P 2000/03/01 A 3 B P 2000/04/01 A 4 B 1999/01/01 - (a) 2 A @ 4 B + (assets) 2 A @ 4 B 2000/01/01 - (a) 1 A @ 6 B + (assets) 1 A @ 6 B 2000/02/01 - (a) 1 A @ 7 B + (assets) 1 A @ 7 B 2000/03/01 - (a) 1 A @ 8 B + (assets) 1 A @ 8 B # 1. multicolumn balance report showing changes in period-end values # Initial balance 2 A, valued at 10 B each, total 20 B @@ -27,29 +27,42 @@ P 2000/04/01 A 4 B $ hledger -f- bal -M --valuechange -b 2000 Period-end value changes in 2000-01-01..2000-04-30: - || Jan Feb Mar Apr -===++====================== - a || -5 B -7 B 7 B 5 B ----++---------------------- - || -5 B -7 B 7 B 5 B + || Jan Feb Mar Apr +========++====================== + assets || -5 B -7 B 7 B 5 B +--------++---------------------- + || -5 B -7 B 7 B 5 B # 2. Cumulative multicolumn balance report showing changes in period-end values $ hledger -f- bal -M --valuechange --cumulative -b 2000 Cumulative period-end value changes in 2000-01-01..2000-04-30: - || 2000-01-31 2000-02-29 2000-03-31 2000-04-30 -===++================================================ - a || -5 B -12 B -5 B 0 ----++------------------------------------------------ - || -5 B -12 B -5 B 0 + || 2000-01-31 2000-02-29 2000-03-31 2000-04-30 +========++================================================ + assets || -5 B -12 B -5 B 0 +--------++------------------------------------------------ + || -5 B -12 B -5 B 0 # 3. Historical multicolumn balance report showing changes in period-end values is # the same as a historical report $ hledger -f- bal -M --valuechange --historical -b 2000 Ending balances (historical) in 2000-01-01..2000-04-30, valued at period ends: - || 2000-01-31 2000-02-29 2000-03-31 2000-04-30 -===++================================================ - a || 15 B 8 B 15 B 20 B ----++------------------------------------------------ - || 15 B 8 B 15 B 20 B + || 2000-01-31 2000-02-29 2000-03-31 2000-04-30 +========++================================================ + assets || 15 B 8 B 15 B 20 B +--------++------------------------------------------------ + || 15 B 8 B 15 B 20 B + +# 4. Balance sheet also reports on value change +$ hledger -f- balancesheet -MN --valuechange --periodic -b 2000 +Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes) + + || Jan Feb Mar Apr +=============++====================== + Assets || +-------------++---------------------- + assets || -5 B -7 B 7 B 5 B +=============++====================== + Liabilities || +-------------++----------------------