fix: Ensure valuation happens after filtration (#2385)

This commit is contained in:
Stephen Morgan 2025-05-13 17:54:35 +10:00 committed by Simon Michael
parent dbf583829a
commit 447a681645
2 changed files with 22 additions and 10 deletions

View File

@ -590,19 +590,11 @@ journalValueAndFilterPostings rspec j = journalValueAndFilterPostingsWith rspec
-- | Like 'journalValueAndFilterPostings', but takes a 'PriceOracle' as an argument.
journalValueAndFilterPostingsWith :: ReportSpec -> Journal -> PriceOracle -> Journal
journalValueAndFilterPostingsWith rspec@ReportSpec{_rsQuery=q, _rsReportOpts=ropts} j =
-- Filter by the remainder of the query
filterJournal reportq
-- Apply valuation and costing
. journalApplyValuationFromOptsWith rspec
-- Filter by amount and currency, so it matches pre-valuation/costing
(if queryIsNull amtsymq then j else filterJournalAmounts amtsymq j)
journalValueAndFilterPostingsWith rspec@ReportSpec{_rsQuery=q, _rsReportOpts=ropts} =
journalApplyValuationFromOptsWith rspec . filterJournal q
where
-- with -r, replace each posting with its sibling postings
filterJournal = if related_ ropts then filterJournalRelatedPostings else filterJournalPostings
amtsymq = dbg3 "amtsymq" $ filterQuery queryIsAmtOrSym q
reportq = dbg3 "reportq" $ filterQuery (not . queryIsAmtOrSym) q
queryIsAmtOrSym = liftA2 (||) queryIsAmt queryIsSym
-- | Convert this journal's postings' amounts to cost and/or to value, if specified
-- by options (-B/--cost/-V/-X/--value etc.). Strip prices if not needed. This

View File

@ -624,3 +624,23 @@ $ hledger -f- print
Assets:BOG:Personal 209.60 GEL
>=
# ** 42. Make sure --cost interacts properly with interval reports with an early end date (#2385)
<
2025-03-02
expenses $1
assets
2025-04-02
expenses $2
assets
$ hledger -f- balance -M -X $ -e 2025-04 -N
Balance changes in 2025-03, valued at period ends:
|| Mar
==========++=====
assets || $-1
expenses || $1
>=0