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} = | subtractAcct a@Account{aibalance=i1,aebalance=e1} Account{aibalance=i2,aebalance=e2} = | ||||||
|     a{aibalance = i1 - i2, aebalance = e1 - 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 | -- | Extract period changes from a cumulative list | ||||||
| periodChanges :: Account -> Map k Account -> Map k Account | periodChanges :: Account -> Map k Account -> Map k Account | ||||||
| periodChanges start amtmap = | 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. |       -- Postings, or summary postings with their subperiod's end date, to be displayed. | ||||||
|       displayps :: [(Posting, Maybe Day)] |       displayps :: [(Posting, Maybe Day)] | ||||||
|         | multiperiod = |         | multiperiod && changingValuation ropts = [(pvalue lastday p, Just periodend) | (p, periodend) <- summariseps reportps, let lastday = addDays (-1) periodend] | ||||||
|             let summaryps = summarisePostingsByInterval interval_ whichdate mdepth showempty reportspan reportps |         | multiperiod                            = [(p, Just periodend) | (p, periodend) <- summariseps valuedps] | ||||||
|             in [(pvalue lastday p, Just periodend) | (p, periodend) <- summaryps, let lastday = addDays (-1) periodend] |         | otherwise                              = [(p, Nothing)        | p <- valuedps] | ||||||
|         | otherwise = |  | ||||||
|             [(pvalue reportorjournallast p, Nothing) | p <- reportps] |  | ||||||
|         where |         where | ||||||
|  |           summariseps = summarisePostingsByInterval interval_ whichdate mdepth showempty reportspan | ||||||
|  |           valuedps = map (pvalue reportorjournallast) reportps | ||||||
|           showempty = empty_ || average_ |           showempty = empty_ || average_ | ||||||
|           reportorjournallast = |           reportorjournallast = | ||||||
|             fromMaybe (error' "postingsReport: expected a non-empty journal") $  -- PARTIAL: shouldn't happen |             fromMaybe (error' "postingsReport: expected a non-empty journal") $  -- PARTIAL: shouldn't happen | ||||||
|  | |||||||
| @ -23,6 +23,7 @@ module Hledger.Reports.ReportOptions ( | |||||||
|   rawOptsToReportSpec, |   rawOptsToReportSpec, | ||||||
|   flat_, |   flat_, | ||||||
|   tree_, |   tree_, | ||||||
|  |   changingValuation, | ||||||
|   reportOptsToggleStatus, |   reportOptsToggleStatus, | ||||||
|   simplifyStatuses, |   simplifyStatuses, | ||||||
|   whichDateFromOpts, |   whichDateFromOpts, | ||||||
| @ -471,6 +472,14 @@ queryFromFlags ReportOpts{..} = simplifyQuery $ And flagsq | |||||||
|     consIf f b = if b then (f True:) else id |     consIf f b = if b then (f True:) else id | ||||||
|     consJust f = maybe id ((:) . f) |     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. | -- Report dates. | ||||||
| 
 | 
 | ||||||
| -- | The effective report span is the start and end dates specified by | -- | 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 | 2020-04-01                      (a)                            4 B          10 B | ||||||
| >=0 | >=0 | ||||||
| 
 | 
 | ||||||
| # 52. --value=then with a report interval. How are the summary amounts valued ? | # 52. --value=then with a report interval. Summary amounts are the sums of the | ||||||
| # Currently each interval's unvalued sum is valued on its first day. | # values of each posting at their posting date. | ||||||
| < | < | ||||||
| P 2020-01-01 A 1 B | P 2020-01-01 A 1 B | ||||||
| P 2020-02-01 A 2 B | P 2020-02-01 A 2 B | ||||||
| @ -624,8 +624,8 @@ P 2020-04-01 A 4 B | |||||||
|    (a)  1 A |    (a)  1 A | ||||||
| 
 | 
 | ||||||
| $ hledger -f- reg --value=then -Q | $ hledger -f- reg --value=then -Q | ||||||
| 2020Q1                  a                                      3 B           3 B | 2020Q1                  a                                      6 B           6 B | ||||||
| 2020Q2                  a                                      4 B           7 B | 2020Q2                  a                                      4 B          10 B | ||||||
| >=0 | >=0 | ||||||
| 
 | 
 | ||||||
| # 53. print --value should affect all postings, including when there's an implicit transaction price | # 53. print --value should affect all postings, including when there's an implicit transaction price | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user