From ce4fcfae84eaa2e77798cd990b6a6d673b582921 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Thu, 23 Sep 2021 15:28:46 +1000 Subject: [PATCH] imp!: value: For register reports with no reporting interval and --value=end, historical reports should be valued at journal/report end date. --- hledger-lib/Hledger/Reports/ReportOptions.hs | 4 +++- hledger/hledger.m4.md | 5 +++-- hledger/test/journal/valuation.test | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index 8f6edb2c7..70b27cac6 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -524,7 +524,9 @@ journalApplyValuationFromOptsWith rspec@ReportSpec{_rsReportOpts=ropts} j priceo -- Find the end of the period containing this posting periodEnd = addDays (-1) . fromMaybe err . mPeriodEnd . postingDate - mPeriodEnd = spanEnd <=< latestSpanContaining (historical : spans) + mPeriodEnd = case interval_ ropts of + NoInterval -> const . spanEnd $ reportSpan j rspec + _ -> spanEnd <=< latestSpanContaining (historical : spans) historical = DateSpan Nothing $ spanStart =<< headMay spans spans = splitSpan (interval_ ropts) $ reportSpanBothDates j rspec styles = journalCommodityStyles j diff --git a/hledger/hledger.m4.md b/hledger/hledger.m4.md index d8b817fe7..adcfd2479 100644 --- a/hledger/hledger.m4.md +++ b/hledger/hledger.m4.md @@ -1261,8 +1261,9 @@ Related: | balance assertions/assignments | unchanged | unchanged | unchanged | unchanged | unchanged | |
| | | | | | | **register** | | | | | | -| starting balance (-H) | cost | value at day before report or journal start | valued at day each historical posting was made | value at day before report or journal start | value at DATE/today | -| posting amounts | cost | value at report end or today | value at posting date | value at report or journal end | value at DATE/today | +| starting balance (-H) | cost | value at report or journal end | valued at day each historical posting was made | value at report or journal end | value at DATE/today | +| starting balance (-H) with report interval | cost | value at day before report or journal start | valued at day each historical posting was made | value at day before report or journal start | value at DATE/today | +| posting amounts | cost | value at report or journal end | value at posting date | value at report or journal end | value at DATE/today | | summary posting amounts with report interval | summarised cost | value at period ends | sum of postings in interval, valued at interval start | value at period ends | value at DATE/today | | running total/average | sum/average of displayed values | sum/average of displayed values | sum/average of displayed values | sum/average of displayed values | sum/average of displayed values | |
| | | | | | diff --git a/hledger/test/journal/valuation.test b/hledger/test/journal/valuation.test index bb820421b..37aa33ea6 100644 --- a/hledger/test/journal/valuation.test +++ b/hledger/test/journal/valuation.test @@ -265,10 +265,10 @@ $ hledger -f- reg --value=cost -b 200002 -H # 23. register with starting balance, valued at period end. # That is unspecified so the last posting date (or price directive date) is used, # ie 2000/4/1, so the price is 4 B. -# Starting balance is 5 B as above. +# Starting balance is 1 A, which is valued at 4 B. $ hledger -f- reg --value=end -b 200002 -H -2000-02-01 (a) 4 B 9 B -2000-03-01 (a) 4 B 13 B +2000-02-01 (a) 4 B 8 B +2000-03-01 (a) 4 B 12 B # 24. register with starting balance, valued at specified date (when the price is 5 B). # Starting balance is 5 B as above.