uses today's prices, not those of last txn date, for -V (fix #683,#648)

This commit is contained in:
Simon Michael 2017-12-29 17:11:17 -08:00
parent f8e781462d
commit 8f55b6137d
3 changed files with 38 additions and 27 deletions

View File

@ -24,9 +24,12 @@ module Hledger.Reports.ReportOptions (
queryOptsFromOpts,
transactionDateFn,
postingDateFn,
reportStartEndDates,
reportStartDate,
reportEndDate,
reportStartEndDates,
specifiedStartEndDates,
specifiedStartDate,
specifiedEndDate,
tests_Hledger_Reports_ReportOptions
)
@ -399,33 +402,42 @@ tests_queryOptsFromOpts = [
})
]
-- | The effective report start date is the one specified by options or queries,
-- otherwise the earliest transaction or posting date in the journal,
-- | The effective report start/end dates are the dates specified by options or queries,
-- otherwise the earliest/latest transaction or posting date in the journal,
-- otherwise (for an empty journal) nothing.
-- Needs IO to parse smart dates in options/queries.
reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day)
reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts
-- | The effective report end date is the one specified by options or queries,
-- otherwise the latest transaction or posting date in the journal,
-- otherwise (for an empty journal) nothing.
-- Needs IO to parse smart dates in options/queries.
reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day)
reportEndDate j ropts = (snd <$>) <$> reportStartEndDates j ropts
reportStartEndDates :: Journal -> ReportOpts -> IO (Maybe (Day,Day))
reportStartEndDates j ropts = do
today <- getCurrentDay
let
q = queryFromOpts today ropts
mrequestedstartdate = queryStartDate False q
mrequestedenddate = queryEndDate False q
(mspecifiedstartdate, mspecifiedenddate) <- specifiedStartEndDates ropts
return $
case journalDateSpan False j of -- don't bother with secondary dates
DateSpan (Just journalstartdate) (Just journalenddate) ->
Just (fromMaybe journalstartdate mrequestedstartdate, fromMaybe journalenddate mrequestedenddate)
Just (fromMaybe journalstartdate mspecifiedstartdate, fromMaybe journalenddate mspecifiedenddate)
_ -> Nothing
reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day)
reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts
reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day)
reportEndDate j ropts = (snd <$>) <$> reportStartEndDates j ropts
-- | The specified report start/end dates are the dates specified by options or queries, if any.
-- Needs IO to parse smart dates in options/queries.
specifiedStartEndDates :: ReportOpts -> IO (Maybe Day, Maybe Day)
specifiedStartEndDates ropts = do
today <- getCurrentDay
let
q = queryFromOpts today ropts
mspecifiedstartdate = queryStartDate False q
mspecifiedenddate = queryEndDate False q
return (mspecifiedstartdate, mspecifiedenddate)
specifiedStartDate :: ReportOpts -> IO (Maybe Day)
specifiedStartDate ropts = fst <$> specifiedStartEndDates ropts
specifiedEndDate :: ReportOpts -> IO (Maybe Day)
specifiedEndDate ropts = snd <$> specifiedStartEndDates ropts
tests_Hledger_Reports_ReportOptions :: Test
tests_Hledger_Reports_ReportOptions = TestList $

View File

@ -117,12 +117,11 @@ anonymise j
-- and seems to have the same effect as doing it last on the reported values.
journalApplyValue :: ReportOpts -> Journal -> IO Journal
journalApplyValue ropts j = do
mvaluedate <- reportEndDate j ropts
let convert | value_ ropts
, Just d <- mvaluedate
= overJournalAmounts (amountValue j d)
| otherwise
= id
today <- getCurrentDay
mspecifiedenddate <- specifiedEndDate ropts
let d = fromMaybe today mspecifiedenddate
convert | value_ ropts = overJournalAmounts (amountValue j d)
| otherwise = id
return $ convert j
-- | Run PeriodicTransactions from journal from today or journal end to requested end day.

View File

@ -28,7 +28,7 @@ P 2011/01/01 GBP $1.35
$135.00 expenses:foreign
>>>=0
# 3. Market prices in the future are not ignored. #453
# 3. Market prices in the future are ignored. #453, #683
hledger -f- bal -N -V
<<<
P 2000/1/1 $ €1.20
@ -37,7 +37,7 @@ P 3000/1/1 $ €1.30
3000/01/02
(a) $100
>>>
€130.00 a
€120.00 a
>>>=0
# 4. The market prices in effect at the report end date are used.