uses today's prices, not those of last txn date, for -V (fix #683,#648)
This commit is contained in:
parent
f8e781462d
commit
8f55b6137d
@ -24,9 +24,12 @@ module Hledger.Reports.ReportOptions (
|
|||||||
queryOptsFromOpts,
|
queryOptsFromOpts,
|
||||||
transactionDateFn,
|
transactionDateFn,
|
||||||
postingDateFn,
|
postingDateFn,
|
||||||
|
reportStartEndDates,
|
||||||
reportStartDate,
|
reportStartDate,
|
||||||
reportEndDate,
|
reportEndDate,
|
||||||
reportStartEndDates,
|
specifiedStartEndDates,
|
||||||
|
specifiedStartDate,
|
||||||
|
specifiedEndDate,
|
||||||
|
|
||||||
tests_Hledger_Reports_ReportOptions
|
tests_Hledger_Reports_ReportOptions
|
||||||
)
|
)
|
||||||
@ -399,33 +402,42 @@ tests_queryOptsFromOpts = [
|
|||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | The effective report start date is the one specified by options or queries,
|
-- | The effective report start/end dates are the dates specified by options or queries,
|
||||||
-- otherwise the earliest transaction or posting date in the journal,
|
-- otherwise the earliest/latest transaction or posting date in the journal,
|
||||||
-- otherwise (for an empty journal) nothing.
|
-- otherwise (for an empty journal) nothing.
|
||||||
-- Needs IO to parse smart dates in options/queries.
|
-- 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 :: Journal -> ReportOpts -> IO (Maybe (Day,Day))
|
||||||
reportStartEndDates j ropts = do
|
reportStartEndDates j ropts = do
|
||||||
today <- getCurrentDay
|
(mspecifiedstartdate, mspecifiedenddate) <- specifiedStartEndDates ropts
|
||||||
let
|
|
||||||
q = queryFromOpts today ropts
|
|
||||||
mrequestedstartdate = queryStartDate False q
|
|
||||||
mrequestedenddate = queryEndDate False q
|
|
||||||
return $
|
return $
|
||||||
case journalDateSpan False j of -- don't bother with secondary dates
|
case journalDateSpan False j of -- don't bother with secondary dates
|
||||||
DateSpan (Just journalstartdate) (Just journalenddate) ->
|
DateSpan (Just journalstartdate) (Just journalenddate) ->
|
||||||
Just (fromMaybe journalstartdate mrequestedstartdate, fromMaybe journalenddate mrequestedenddate)
|
Just (fromMaybe journalstartdate mspecifiedstartdate, fromMaybe journalenddate mspecifiedenddate)
|
||||||
_ -> Nothing
|
_ -> 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 :: Test
|
||||||
tests_Hledger_Reports_ReportOptions = TestList $
|
tests_Hledger_Reports_ReportOptions = TestList $
|
||||||
|
|||||||
@ -117,12 +117,11 @@ anonymise j
|
|||||||
-- and seems to have the same effect as doing it last on the reported values.
|
-- and seems to have the same effect as doing it last on the reported values.
|
||||||
journalApplyValue :: ReportOpts -> Journal -> IO Journal
|
journalApplyValue :: ReportOpts -> Journal -> IO Journal
|
||||||
journalApplyValue ropts j = do
|
journalApplyValue ropts j = do
|
||||||
mvaluedate <- reportEndDate j ropts
|
today <- getCurrentDay
|
||||||
let convert | value_ ropts
|
mspecifiedenddate <- specifiedEndDate ropts
|
||||||
, Just d <- mvaluedate
|
let d = fromMaybe today mspecifiedenddate
|
||||||
= overJournalAmounts (amountValue j d)
|
convert | value_ ropts = overJournalAmounts (amountValue j d)
|
||||||
| otherwise
|
| otherwise = id
|
||||||
= id
|
|
||||||
return $ convert j
|
return $ convert j
|
||||||
|
|
||||||
-- | Run PeriodicTransactions from journal from today or journal end to requested end day.
|
-- | Run PeriodicTransactions from journal from today or journal end to requested end day.
|
||||||
|
|||||||
@ -28,7 +28,7 @@ P 2011/01/01 GBP $1.35
|
|||||||
$135.00 expenses:foreign
|
$135.00 expenses:foreign
|
||||||
>>>=0
|
>>>=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
|
hledger -f- bal -N -V
|
||||||
<<<
|
<<<
|
||||||
P 2000/1/1 $ €1.20
|
P 2000/1/1 $ €1.20
|
||||||
@ -37,7 +37,7 @@ P 3000/1/1 $ €1.30
|
|||||||
3000/01/02
|
3000/01/02
|
||||||
(a) $100
|
(a) $100
|
||||||
>>>
|
>>>
|
||||||
€130.00 a
|
€120.00 a
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# 4. The market prices in effect at the report end date are used.
|
# 4. The market prices in effect at the report end date are used.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user