mirror of
https://github.com/simonmichael/hledger.git
synced 2025-01-06 10:40:37 +03:00
lib: Calculate value at posting date for register --value=then -M.
This commit is contained in:
parent
07a9f11962
commit
2b545caae5
@ -560,14 +560,6 @@ subtractAcct :: Account -> Account -> Account
|
||||
subtractAcct a@Account{aibalance=i1,aebalance=e1} Account{aibalance=i2,aebalance=e2} =
|
||||
a{aibalance = i1 - i2, aebalance = e1 - e2}
|
||||
|
||||
-- | Whether the market price for postings might change when reported in
|
||||
-- different report periods.
|
||||
changingValuation :: ReportOpts -> Bool
|
||||
changingValuation ropts = case value_ ropts of
|
||||
Just (AtCost (Just _)) -> True
|
||||
Just (AtEnd _) -> True
|
||||
_ -> False
|
||||
|
||||
-- | Extract period changes from a cumulative list
|
||||
periodChanges :: Account -> Map k Account -> Map k Account
|
||||
periodChanges start amtmap =
|
||||
|
@ -80,12 +80,12 @@ postingsReport rspec@ReportSpec{rsOpts=ropts@ReportOpts{..}} j = items
|
||||
|
||||
-- Postings, or summary postings with their subperiod's end date, to be displayed.
|
||||
displayps :: [(Posting, Maybe Day)]
|
||||
| multiperiod =
|
||||
let summaryps = summarisePostingsByInterval interval_ whichdate mdepth showempty reportspan reportps
|
||||
in [(pvalue lastday p, Just periodend) | (p, periodend) <- summaryps, let lastday = addDays (-1) periodend]
|
||||
| otherwise =
|
||||
[(pvalue reportorjournallast p, Nothing) | p <- reportps]
|
||||
| multiperiod && changingValuation ropts = [(pvalue lastday p, Just periodend) | (p, periodend) <- summariseps reportps, let lastday = addDays (-1) periodend]
|
||||
| multiperiod = [(p, Just periodend) | (p, periodend) <- summariseps valuedps]
|
||||
| otherwise = [(p, Nothing) | p <- valuedps]
|
||||
where
|
||||
summariseps = summarisePostingsByInterval interval_ whichdate mdepth showempty reportspan
|
||||
valuedps = map (pvalue reportorjournallast) reportps
|
||||
showempty = empty_ || average_
|
||||
reportorjournallast =
|
||||
fromMaybe (error' "postingsReport: expected a non-empty journal") $ -- PARTIAL: shouldn't happen
|
||||
|
@ -23,6 +23,7 @@ module Hledger.Reports.ReportOptions (
|
||||
rawOptsToReportSpec,
|
||||
flat_,
|
||||
tree_,
|
||||
changingValuation,
|
||||
reportOptsToggleStatus,
|
||||
simplifyStatuses,
|
||||
whichDateFromOpts,
|
||||
@ -471,6 +472,14 @@ queryFromFlags ReportOpts{..} = simplifyQuery $ And flagsq
|
||||
consIf f b = if b then (f True:) else id
|
||||
consJust f = maybe id ((:) . f)
|
||||
|
||||
-- | Whether the market price for postings might change when reported in
|
||||
-- different report periods.
|
||||
changingValuation :: ReportOpts -> Bool
|
||||
changingValuation ropts = case value_ ropts of
|
||||
Just (AtCost (Just _)) -> True
|
||||
Just (AtEnd _) -> True
|
||||
_ -> False
|
||||
|
||||
-- Report dates.
|
||||
|
||||
-- | The effective report span is the start and end dates specified by
|
||||
|
@ -603,8 +603,8 @@ $ hledger -f- reg --value=then -b 2020-03 -H
|
||||
2020-04-01 (a) 4 B 10 B
|
||||
>=0
|
||||
|
||||
# 52. --value=then with a report interval. How are the summary amounts valued ?
|
||||
# Currently each interval's unvalued sum is valued on its first day.
|
||||
# 52. --value=then with a report interval. Summary amounts are the sums of the
|
||||
# values of each posting at their posting date.
|
||||
<
|
||||
P 2020-01-01 A 1 B
|
||||
P 2020-02-01 A 2 B
|
||||
@ -624,8 +624,8 @@ P 2020-04-01 A 4 B
|
||||
(a) 1 A
|
||||
|
||||
$ hledger -f- reg --value=then -Q
|
||||
2020Q1 a 3 B 3 B
|
||||
2020Q2 a 4 B 7 B
|
||||
2020Q1 a 6 B 6 B
|
||||
2020Q2 a 4 B 10 B
|
||||
>=0
|
||||
|
||||
# 53. print --value should affect all postings, including when there's an implicit transaction price
|
||||
|
Loading…
Reference in New Issue
Block a user