imp: prices: use --infer-market-prices instead of --costs

This command now reuses the --infer-market-prices flag, and uses
a new --infer-reverse-prices flag, instead of the old
--costs and --inverted-costs flags, which are now deprecated and hidden.
This commit is contained in:
Simon Michael 2021-09-09 13:03:08 -10:00
parent 326d6e8dae
commit 9dca1dc7b6
5 changed files with 38 additions and 22 deletions

View File

@ -184,12 +184,17 @@ reportflags = [
,"'now': convert to current market value, in default valuation commodity or COMM"
,"YYYY-MM-DD: convert to market value on the given date, in default valuation commodity or COMM"
])
-- history of this flag:
-- history of this flag so far, lest we be confused:
-- originally --infer-value
-- 2021-02, --infer-market-price added, --infer-value deprecated
-- 2021-09, --infer-value hidden
-- 2021-02 --infer-market-price added, --infer-value deprecated
-- 2021-09
-- --infer-value hidden
-- --infer-market-price renamed to --infer-market-prices, old spelling still works
-- ReportOptions{infer_value_} renamed to infer_prices_ (and BalancingOpts{infer_prices_} renamed to infer_transaction_prices_)
-- ReportOptions{infer_value_} renamed to infer_prices_, BalancingOpts{infer_prices_} renamed to infer_transaction_prices_
-- some related prices command changes
-- --costs deprecated and hidden, uses --infer-market-prices instead
-- --inverted-costs renamed to --infer-reverse-prices
,flagNone ["infer-market-prices"] (setboolopt "infer-market-prices")
"use transaction prices (recorded with @ or @@) as additional market prices, as if they were P directives"

View File

@ -19,10 +19,13 @@ import System.Console.CmdArgs.Explicit
pricesmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Prices.txt")
[flagNone ["costs"] (setboolopt "costs") "print transaction prices from postings"
,flagNone ["inverted-costs"] (setboolopt "inverted-costs") "print transaction inverted prices from postings also"]
[flagNone ["infer-reverse-prices"] (setboolopt "infer-reverse-prices") "also show prices obtained by inverting transaction prices"
]
[generalflagsgroup1]
hiddenflags
(hiddenflags ++
[flagNone ["costs"] (setboolopt "infer-market-prices") "deprecated, use --infer-market-prices instead"
,flagNone ["inverted-costs"] (setboolopt "infer-reverse-prices") "deprecated, use --infer-reverse-prices instead"
])
([], Just $ argsFlag "[QUERY]")
-- XXX the original hledger-prices script always ignored assertions
@ -32,9 +35,18 @@ prices opts j = do
q = _rsQuery $ reportspec_ opts
ps = filter (matchesPosting q) $ allPostings j
mprices = jpricedirectives j
cprices = map (stylePriceDirectiveExceptPrecision styles) $ concatMap postingsPriceDirectivesFromCosts ps
icprices = map (stylePriceDirectiveExceptPrecision styles) $ concatMap (postingsPriceDirectivesFromCosts . postingTransformAmount (mapMixedAmount invertPrice)) ps
allprices = mprices ++ ifBoolOpt "costs" cprices ++ ifBoolOpt "inverted-costs" icprices
cprices =
map (stylePriceDirectiveExceptPrecision styles) $
concatMap postingsPriceDirectivesFromCosts ps
rcprices =
map (stylePriceDirectiveExceptPrecision styles) $
concatMap (postingsPriceDirectivesFromCosts . postingTransformAmount (mapMixedAmount invertPrice))
ps
allprices =
mprices
++ ifBoolOpt "infer-market-prices" cprices
++ ifBoolOpt "infer-reverse-prices" rcprices -- TODO: shouldn't this show reversed P prices also ? valuation will use them
mapM_ (T.putStrLn . showPriceDirective) $
sortOn pddate $
filter (matchesPriceDirective q) $

View File

@ -1,8 +1,8 @@
prices\
Print [market price directives](https://hledger.org/manual#market-prices) from the journal.
With --costs, also print synthetic market prices based on [transaction prices](https://hledger.org/manual#transaction-prices).
With --inverted-costs, also print inverse prices based on transaction prices.
Prices (and postings providing prices) can be filtered by a query.
Price amounts are always displayed with their full precision.
With --infer-market-prices, generate additional market prices from [transaction prices](https://hledger.org/manual#transaction-prices).
With --infer-reverse-prices, also generate market prices by inverting transaction prices.
Prices (and postings providing transaction prices) can be filtered by a query.
Price amounts are displayed with their full precision.
_FLAGS

View File

@ -1600,7 +1600,6 @@ read -r -d "" _hledger_complist_options_prices <<"__TEXT__"
--cleared
--color=
--cost
--costs
--daily
--date2
--debug=
@ -1613,8 +1612,8 @@ read -r -d "" _hledger_complist_options_prices <<"__TEXT__"
--help
--ignore-assertions
--infer-market-prices
--infer-reverse-prices
--info
--inverted-costs
--man
--market
--monthly

View File

@ -32,13 +32,13 @@ P 2016/2/1 EUR $1.05
2016/1/3 spend
expenses 20 EUR @@ $21.45
assets:bank
$ hledger prices -f- --costs
$ hledger prices -f- --infer-market-prices
P 2016-01-01 EUR $1.06
P 2016-01-02 EUR $1.07
P 2016-01-03 EUR $1.0725
P 2016-02-01 EUR $1.05
# 3. inverted costs from postings can be calculated
# 3. inverted prices can be calculated
<
P 2016/1/1 EUR $1.06
P 2016/2/1 EUR $1.05
@ -51,7 +51,7 @@ P 2016/2/1 EUR $1.05
2016/1/3 spend
expenses $21.45 @@ 20.00 EUR
assets:bank
$ hledger prices -f- --inverted-costs
$ hledger prices -f- --infer-reverse-prices
P 2016-01-01 EUR $1.06
P 2016-01-03 EUR $1.0725
P 2016-02-01 EUR $1.05
@ -74,7 +74,7 @@ P 2019-01-01 X 1.000,123 A
P 2019-01-02 X 1.000,1 A
# 5. Commodity styles aren't yet applied to prices inferred from transaction prices.
$ hledger -f- prices --costs
$ hledger -f- prices --infer-market-prices
P 2019-01-01 X 1.000,123 A
P 2019-01-02 X 1.000,1 A
P 2019-02-01 X 1.000,2345 A