;refactor: extract --value=then error message

This commit is contained in:
Simon Michael 2020-02-24 16:16:14 -08:00
parent 8b520b5c3e
commit 7f16d23898
4 changed files with 9 additions and 4 deletions

View File

@ -15,6 +15,7 @@ module Hledger.Data.Valuation (
ValuationType(..) ValuationType(..)
,PriceOracle ,PriceOracle
,journalPriceOracle ,journalPriceOracle
,unsupportedValueThenError
-- ,amountApplyValuation -- ,amountApplyValuation
-- ,amountValueAtDate -- ,amountValueAtDate
,mixedAmountApplyValuation ,mixedAmountApplyValuation
@ -137,7 +138,7 @@ amountApplyValuation priceoracle styles periodlast mreportlast today ismultiperi
case v of case v of
AtCost Nothing -> amountToCost styles a AtCost Nothing -> amountToCost styles a
AtCost mc -> amountValueAtDate priceoracle styles mc periodlast $ amountToCost styles a AtCost mc -> amountValueAtDate priceoracle styles mc periodlast $ amountToCost styles a
AtThen _mc -> error' "Sorry, --value=then is not yet implemented for this kind of report." -- TODO AtThen _mc -> error' unsupportedValueThenError -- TODO
-- amountValueAtDate priceoracle styles mc periodlast a -- posting date unknown, handle like AtEnd -- amountValueAtDate priceoracle styles mc periodlast a -- posting date unknown, handle like AtEnd
AtEnd mc -> amountValueAtDate priceoracle styles mc periodlast a AtEnd mc -> amountValueAtDate priceoracle styles mc periodlast a
AtNow mc -> amountValueAtDate priceoracle styles mc today a AtNow mc -> amountValueAtDate priceoracle styles mc today a
@ -145,6 +146,10 @@ amountApplyValuation priceoracle styles periodlast mreportlast today ismultiperi
AtDefault mc -> amountValueAtDate priceoracle styles mc (fromMaybe today mreportlast) a AtDefault mc -> amountValueAtDate priceoracle styles mc (fromMaybe today mreportlast) a
AtDate d mc -> amountValueAtDate priceoracle styles mc d a AtDate d mc -> amountValueAtDate priceoracle styles mc d a
-- | Standard error message for a report not supporting --value=then.
unsupportedValueThenError :: String
unsupportedValueThenError = "Sorry, --value=then is not yet implemented for this kind of report."
-- | Find the market value of each component amount in the given -- | Find the market value of each component amount in the given
-- commodity, or its default valuation commodity, at the given -- commodity, or its default valuation commodity, at the given
-- valuation date, using the given market price oracle. -- valuation date, using the given market price oracle.

View File

@ -253,7 +253,7 @@ budgetReportAsText ropts@ReportOpts{..} budgetr =
(showDateSpan $ periodicReportSpan budgetr) (showDateSpan $ periodicReportSpan budgetr)
(case value_ of (case value_ of
Just (AtCost _mc) -> ", valued at cost" Just (AtCost _mc) -> ", valued at cost"
Just (AtThen _mc) -> error' "Sorry, --value=then is not yet implemented for this kind of report." -- TODO Just (AtThen _mc) -> error' unsupportedValueThenError -- TODO
Just (AtEnd _mc) -> ", valued at period ends" Just (AtEnd _mc) -> ", valued at period ends"
Just (AtNow _mc) -> ", current value" Just (AtNow _mc) -> ", current value"
-- XXX duplicates the above -- XXX duplicates the above

View File

@ -587,7 +587,7 @@ multiBalanceReportAsText ropts@ReportOpts{..} r =
(showDateSpan $ periodicReportSpan r) (showDateSpan $ periodicReportSpan r)
(case value_ of (case value_ of
Just (AtCost _mc) -> ", valued at cost" Just (AtCost _mc) -> ", valued at cost"
Just (AtThen _mc) -> error' "Sorry, --value=then is not yet implemented for this kind of report." -- TODO -- ", valued at period ends" -- handled like AtEnd for now Just (AtThen _mc) -> error' unsupportedValueThenError -- TODO -- ", valued at period ends" -- handled like AtEnd for now
Just (AtEnd _mc) -> ", valued at period ends" Just (AtEnd _mc) -> ", valued at period ends"
Just (AtNow _mc) -> ", current value" Just (AtNow _mc) -> ", current value"
-- XXX duplicates the above -- XXX duplicates the above

View File

@ -217,7 +217,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
valuationdesc = case value_ of valuationdesc = case value_ of
Just (AtCost _mc) -> ", valued at cost" Just (AtCost _mc) -> ", valued at cost"
Just (AtThen _mc) -> error' "Sorry, --value=then is not yet implemented for this kind of report." -- TODO Just (AtThen _mc) -> error' unsupportedValueThenError -- TODO
Just (AtEnd _mc) -> ", valued at period ends" Just (AtEnd _mc) -> ", valued at period ends"
Just (AtNow _mc) -> ", current value" Just (AtNow _mc) -> ", current value"
Just (AtDefault _mc) | multiperiod -> ", valued at period ends" Just (AtDefault _mc) | multiperiod -> ", valued at period ends"