reg: fix --value-at=transaction with -M (#329)

This commit is contained in:
Simon Michael 2019-05-06 08:07:16 -07:00
parent 30a35230d2
commit 72214a5747
3 changed files with 50 additions and 11 deletions

View File

@ -95,11 +95,12 @@ postingsReport ropts@ReportOpts{..} q j =
if multiperiod then if multiperiod then
let let
showempty = empty_ || average_ showempty = empty_ || average_
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan reportps -- for --value-at=transaction, need to value the postings before summarising them
maybevaluedreportps
| mvalueat==Just AtTransaction = [postingValueAtDate j (postingDate p) p | p <- reportps]
| otherwise = reportps
summaryps = summarisePostingsByInterval interval_ whichdate depth showempty reportspan maybevaluedreportps
in case mvalueat of in case mvalueat of
Nothing -> [(p , periodend) | (p,periodend) <- summaryps]
Just AtTransaction -> [(postingValueAtDate j (postingDate p) p , periodend) | (p,periodend) <- summaryps]
-- ^ XXX shouldn't this value the individual ps at postingdate before summarising
Just AtPeriod -> [(postingValueAtDate j periodlastday p , periodend) | (p,periodend) <- summaryps Just AtPeriod -> [(postingValueAtDate j periodlastday p , periodend) | (p,periodend) <- summaryps
,let periodlastday = maybe ,let periodlastday = maybe
(error' "postingsReport: expected a subperiod end date") -- XXX shouldn't happen (error' "postingsReport: expected a subperiod end date") -- XXX shouldn't happen
@ -108,6 +109,7 @@ postingsReport ropts@ReportOpts{..} q j =
] ]
Just AtNow -> [(postingValueAtDate j today p , periodend) | (p,periodend) <- summaryps] Just AtNow -> [(postingValueAtDate j today p , periodend) | (p,periodend) <- summaryps]
Just (AtDate d) -> [(postingValueAtDate j d p , periodend) | (p,periodend) <- summaryps] Just (AtDate d) -> [(postingValueAtDate j d p , periodend) | (p,periodend) <- summaryps]
_ -> summaryps
else else
let reportperiodlastday = let reportperiodlastday =
fromMaybe (error' "postingsReport: expected a non-empty journal") -- XXX shouldn't happen fromMaybe (error' "postingsReport: expected a non-empty journal") -- XXX shouldn't happen
@ -119,8 +121,6 @@ postingsReport ropts@ReportOpts{..} q j =
Just AtNow -> [(postingValueAtDate j today p , Nothing) | p <- reportps] Just AtNow -> [(postingValueAtDate j today p , Nothing) | p <- reportps]
Just (AtDate d) -> [(postingValueAtDate j d p , Nothing) | p <- reportps] Just (AtDate d) -> [(postingValueAtDate j d p , Nothing) | p <- reportps]
-- For -H: postings preceding the report period, to calculate the initial running total/average.
-- posting report items ready for display -- posting report items ready for display
items = dbg1 "postingsReport items" $ postingsReportItems displayps (nullposting,Nothing) whichdate depth valuedstartbal runningcalc startnum items = dbg1 "postingsReport items" $ postingsReportItems displayps (nullposting,Nothing) whichdate depth valuedstartbal runningcalc startnum
where where

View File

@ -611,7 +611,7 @@ types, "-M" means any report interval, "Y" means supported):
|-----------------------|:--------------------------------:|:---------------------------:|:-------------------------------:| |-----------------------|:--------------------------------:|:---------------------------:|:-------------------------------:|
| print | Y | Y | Y | | print | Y | Y | Y |
| register | Y | Y | Y | | register | Y | Y | Y |
| register&nbsp;-M | *retest* | Y | Y | | register&nbsp;-M | Y | Y | Y |
| register&nbsp;-H | Y | Y | Y | | register&nbsp;-H | Y | Y | Y |
| balance | Y | Y | Y | | balance | Y | Y | Y |
| balance&nbsp;-MTA | Y | Y | Y | | balance&nbsp;-MTA | Y | Y | Y |

View File

@ -255,12 +255,51 @@ $ hledger -f- reg --value-at=2000-01-15 -b 200002 -H
# register, periodic # register, periodic
# 22. periodic register report valued at transaction # 22. periodic register report valued at transaction.
# The total for january is 6 B (1 A valued at 1/1, price 1 B, and 1 A
# valued at 1/20, price 5 B).
# Need an extra transaction for this test:
<
P 2000/01/01 A 1 B
P 2000/01/15 A 5 B
P 2000/02/01 A 2 B
P 2000/03/01 A 3 B
P 2000/04/01 A 4 B
2000/01/01
(a) 1 A
2000/01/20
(a) 1 A
2000/02/01
(a) 1 A
2000/03/01
(a) 1 A
$ hledger -f- reg --value-at=transaction -M $ hledger -f- reg --value-at=transaction -M
2000/01 a 1 B 1 B 2000/01 a 6 B 6 B
2000/02 a 2 B 3 B 2000/02 a 2 B 8 B
2000/03 a 3 B 6 B 2000/03 a 3 B 11 B
# back to the original test journal:
<
P 2000/01/01 A 1 B
P 2000/01/15 A 5 B
P 2000/02/01 A 2 B
P 2000/03/01 A 3 B
P 2000/04/01 A 4 B
2000/01/01
(a) 1 A
2000/02/01
(a) 1 A
2000/03/01
(a) 1 A
# 23. periodic register report valued at period end # 23. periodic register report valued at period end
$ hledger -f- reg --value-at=period -M $ hledger -f- reg --value-at=period -M
2000/01 a 5 B 5 B 2000/01 a 5 B 5 B