lib: Default to PeriodChange report when using ValueChangeReport.
This commit is contained in:
parent
3f408c2117
commit
efb37c3343
@ -22,6 +22,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
updateReportSpec,
|
updateReportSpec,
|
||||||
updateReportSpecWith,
|
updateReportSpecWith,
|
||||||
rawOptsToReportSpec,
|
rawOptsToReportSpec,
|
||||||
|
balanceTypeOverride,
|
||||||
flat_,
|
flat_,
|
||||||
tree_,
|
tree_,
|
||||||
reportOptsToggleStatus,
|
reportOptsToggleStatus,
|
||||||
@ -190,7 +191,7 @@ rawOptsToReportOpts rawopts = do
|
|||||||
Just (Right x) -> return x
|
Just (Right x) -> return x
|
||||||
Just (Left err) -> fail $ "could not parse format option: " ++ err
|
Just (Left err) -> fail $ "could not parse format option: " ++ err
|
||||||
|
|
||||||
let reportopts = defreportopts
|
return defreportopts
|
||||||
{period_ = periodFromRawOpts d rawopts
|
{period_ = periodFromRawOpts d rawopts
|
||||||
,interval_ = intervalFromRawOpts rawopts
|
,interval_ = intervalFromRawOpts rawopts
|
||||||
,statuses_ = statusesFromRawOpts rawopts
|
,statuses_ = statusesFromRawOpts rawopts
|
||||||
@ -225,16 +226,6 @@ rawOptsToReportOpts rawopts = do
|
|||||||
,transpose_ = boolopt "transpose" rawopts
|
,transpose_ = boolopt "transpose" rawopts
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustReportDefaults reportopts
|
|
||||||
|
|
||||||
-- | Warn users about option combinations which produce uninteresting results.
|
|
||||||
adjustReportDefaults :: ReportOpts -> IO ReportOpts
|
|
||||||
adjustReportDefaults ropts = case reporttype_ ropts of
|
|
||||||
ValueChangeReport -> case fromMaybe (AtEnd Nothing) $ value_ ropts of
|
|
||||||
v@(AtEnd _) -> return ropts{value_=Just v} -- Set value_ to AtEnd by default, unless overridden
|
|
||||||
_ -> fail "--valuechange only produces sensible results with --value=end"
|
|
||||||
_ -> return ropts
|
|
||||||
|
|
||||||
-- | The result of successfully parsing a ReportOpts on a particular
|
-- | The result of successfully parsing a ReportOpts on a particular
|
||||||
-- Day. Any ambiguous dates are completed and Queries are parsed,
|
-- Day. Any ambiguous dates are completed and Queries are parsed,
|
||||||
-- ensuring that there are no regular expression errors. Values here
|
-- ensuring that there are no regular expression errors. Values here
|
||||||
@ -306,13 +297,19 @@ reporttypeopt =
|
|||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
balancetypeopt :: RawOpts -> BalanceType
|
balancetypeopt :: RawOpts -> BalanceType
|
||||||
balancetypeopt =
|
balancetypeopt = fromMaybe PeriodChange . balanceTypeOverride
|
||||||
fromMaybe PeriodChange . choiceopt parse where
|
|
||||||
|
balanceTypeOverride :: RawOpts -> Maybe BalanceType
|
||||||
|
balanceTypeOverride rawopts = choiceopt parse rawopts <|> reportbal
|
||||||
|
where
|
||||||
parse = \case
|
parse = \case
|
||||||
"historical" -> Just HistoricalBalance
|
"historical" -> Just HistoricalBalance
|
||||||
"cumulative" -> Just CumulativeChange
|
"cumulative" -> Just CumulativeChange
|
||||||
"change" -> Just PeriodChange
|
"change" -> Just PeriodChange
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
reportbal = case reporttypeopt rawopts of
|
||||||
|
ValueChangeReport -> Just PeriodChange
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
-- Get the period specified by any -b/--begin, -e/--end and/or -p/--period
|
-- Get the period specified by any -b/--begin, -e/--end and/or -p/--period
|
||||||
-- options appearing in the command line.
|
-- options appearing in the command line.
|
||||||
@ -440,17 +437,25 @@ reportOptsToggleStatus s ropts@ReportOpts{statuses_=ss}
|
|||||||
-- allowed to combine -B/--cost with any other valuation type. If
|
-- allowed to combine -B/--cost with any other valuation type. If
|
||||||
-- there's more than one valuation type, the rightmost flag wins.
|
-- there's more than one valuation type, the rightmost flag wins.
|
||||||
valuationTypeFromRawOpts :: RawOpts -> (Costing, Maybe ValuationType)
|
valuationTypeFromRawOpts :: RawOpts -> (Costing, Maybe ValuationType)
|
||||||
valuationTypeFromRawOpts rawopts = (costing, lastMay $ mapMaybe snd valuationopts)
|
valuationTypeFromRawOpts rawopts = (costing, valuation)
|
||||||
where
|
where
|
||||||
costing = if (any ((Cost==) . fst) valuationopts) then Cost else NoCost
|
costing = if (any ((Cost==) . fst) valuationopts) then Cost else NoCost
|
||||||
|
valuation = case reporttypeopt rawopts of
|
||||||
|
ValueChangeReport -> case directval of
|
||||||
|
Nothing -> Just $ AtEnd Nothing -- If no valuation requested for valuechange, use AtEnd
|
||||||
|
Just (AtEnd _) -> directval -- If AtEnd valuation requested, use it
|
||||||
|
Just _ -> usageError "--valuechange only produces sensible results with --value=end"
|
||||||
|
_ -> directval -- Otherwise, use requested valuation
|
||||||
|
where directval = lastMay $ mapMaybe snd valuationopts
|
||||||
|
|
||||||
valuationopts = collectopts valuationfromrawopt rawopts
|
valuationopts = collectopts valuationfromrawopt rawopts
|
||||||
valuationfromrawopt (n,v) -- option name, value
|
valuationfromrawopt (n,v) -- option name, value
|
||||||
| n == "B" = Just (Cost, Nothing)
|
| n == "B" = Just (Cost, Nothing)
|
||||||
| n == "V" = Just (NoCost, Just $ AtEnd Nothing)
|
| n == "V" = Just (NoCost, Just $ AtEnd Nothing)
|
||||||
| n == "X" = Just (NoCost, Just $ AtEnd (Just $ T.pack v))
|
| n == "X" = Just (NoCost, Just $ AtEnd (Just $ T.pack v))
|
||||||
| n == "value" = Just $ valuation v
|
| n == "value" = Just $ valueopt v
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
valuation v
|
valueopt v
|
||||||
| t `elem` ["cost","c"] = (Cost, usageError "--value=cost,COMM is no longer supported, please specify valuation explicitly, e.g. --cost --value=then,COMM" <$ mc)
|
| t `elem` ["cost","c"] = (Cost, usageError "--value=cost,COMM is no longer supported, please specify valuation explicitly, e.g. --cost --value=then,COMM" <$ mc)
|
||||||
| t `elem` ["then" ,"t"] = (NoCost, Just $ AtThen mc)
|
| t `elem` ["then" ,"t"] = (NoCost, Just $ AtThen mc)
|
||||||
| t `elem` ["end" ,"e"] = (NoCost, Just $ AtEnd mc)
|
| t `elem` ["end" ,"e"] = (NoCost, Just $ AtEnd mc)
|
||||||
|
|||||||
@ -106,13 +106,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
|
|||||||
where
|
where
|
||||||
ropts@ReportOpts{..} = rsOpts rspec
|
ropts@ReportOpts{..} = rsOpts rspec
|
||||||
-- use the default balance type for this report, unless the user overrides
|
-- use the default balance type for this report, unless the user overrides
|
||||||
mBalanceTypeOverride =
|
mBalanceTypeOverride = balanceTypeOverride rawopts
|
||||||
choiceopt parse rawopts where
|
|
||||||
parse = \case
|
|
||||||
"historical" -> Just HistoricalBalance
|
|
||||||
"cumulative" -> Just CumulativeChange
|
|
||||||
"change" -> Just PeriodChange
|
|
||||||
_ -> Nothing
|
|
||||||
balancetype = fromMaybe cbctype mBalanceTypeOverride
|
balancetype = fromMaybe cbctype mBalanceTypeOverride
|
||||||
-- Set balance type in the report options.
|
-- Set balance type in the report options.
|
||||||
ropts' = ropts{balancetype_=balancetype}
|
ropts' = ropts{balancetype_=balancetype}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ Ending balances (historical) in 2000-01-01..2000-04-30, valued at period ends:
|
|||||||
|| 15 B 8 B 15 B 20 B
|
|| 15 B 8 B 15 B 20 B
|
||||||
|
|
||||||
# 4. Balance sheet also reports on value change
|
# 4. Balance sheet also reports on value change
|
||||||
$ hledger -f- balancesheet -MN --valuechange --change -b 2000
|
$ hledger -f- balancesheet -MN --valuechange -b 2000
|
||||||
Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes)
|
Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes)
|
||||||
|
|
||||||
|| Jan Feb Mar Apr
|
|| Jan Feb Mar Apr
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user