lib, ui, web: stricter accountTransactionsReport filtering

accountTransactionsReport now filters transactions more thoroughly, so
eg transactions dated outside the report period will not be shown.
Previously the transaction would be shown if it had any posting dated
inside the report period. Possibly some other filter criteria now get
applied that didn't before. I think on balance this will give slightly
preferable results.
This commit is contained in:
Simon Michael 2020-07-10 21:52:02 -07:00
parent bf2fe3d88e
commit 3f86bd545f

View File

@ -29,9 +29,10 @@ import Hledger.Utils
-- | An account transactions report represents transactions affecting -- | An account transactions report represents transactions affecting
-- a particular account (or possibly several accounts, but we don't -- a particular account (or possibly several accounts, but we don't
-- use that). It is used eg by hledger-ui's and hledger-web's account -- use that). It is used eg by hledger-ui's and hledger-web's register
-- register view, where we want to show one row per transaction, in -- view, and hledger's aregister report, where we want to show one row
-- the context of the current account. Report items consist of: -- per transaction, in the context of the current account. Report
-- items consist of:
-- --
-- - the transaction, unmodified -- - the transaction, unmodified
-- --
@ -84,7 +85,7 @@ balancelabel = "Historical Total"
accountTransactionsReport :: ReportOpts -> Journal -> Query -> Query -> AccountTransactionsReport accountTransactionsReport :: ReportOpts -> Journal -> Query -> Query -> AccountTransactionsReport
accountTransactionsReport ropts j reportq thisacctq = (label, items) accountTransactionsReport ropts j reportq thisacctq = (label, items)
where where
-- a depth limit does not affect the account transactions report -- a depth limit should not affect the account transactions report
-- seems unnecessary for some reason XXX -- seems unnecessary for some reason XXX
reportq' = -- filterQuery (not . queryIsDepth) reportq' = -- filterQuery (not . queryIsDepth)
reportq reportq
@ -116,7 +117,8 @@ accountTransactionsReport ropts j reportq thisacctq = (label, items)
ts4 = map tval ts3 ts4 = map tval ts3
-- sort by the transaction's register date, for accurate starting balance -- sort by the transaction's register date, for accurate starting balance
ts = sortBy (comparing (transactionRegisterDate reportq' thisacctq)) ts4 -- these are not yet filtered by tdate, we want to search them all for priorps
ts5 = sortBy (comparing (transactionRegisterDate reportq' thisacctq)) ts4
(startbal,label) (startbal,label)
| balancetype_ ropts == HistoricalBalance = (sumPostings priorps, balancelabel) | balancetype_ ropts == HistoricalBalance = (sumPostings priorps, balancelabel)
@ -126,7 +128,7 @@ accountTransactionsReport ropts j reportq thisacctq = (label, items)
filter (matchesPosting filter (matchesPosting
(dbg1 "priorq" $ (dbg1 "priorq" $
And [thisacctq, tostartdateq, datelessreportq])) And [thisacctq, tostartdateq, datelessreportq]))
$ transactionsPostings ts $ transactionsPostings ts5
tostartdateq = tostartdateq =
case mstartdate of case mstartdate of
Just _ -> Date (DateSpan Nothing mstartdate) Just _ -> Date (DateSpan Nothing mstartdate)
@ -134,8 +136,15 @@ accountTransactionsReport ropts j reportq thisacctq = (label, items)
mstartdate = queryStartDate (date2_ ropts) reportq' mstartdate = queryStartDate (date2_ ropts) reportq'
datelessreportq = filterQuery (not . queryIsDateOrDate2) reportq' datelessreportq = filterQuery (not . queryIsDateOrDate2) reportq'
-- now should we include only transactions dated inside report period ?
-- or all transactions with any posting inside the report period ? an option ?
-- filtering might apply some other query terms here too. I think we should.
filtertxns = True
items = reverse $ items = reverse $
accountTransactionsReportItems reportq' thisacctq startbal negate ts accountTransactionsReportItems reportq' thisacctq startbal negate $
(if filtertxns then filter (reportq' `matchesTransaction`) else id) $
ts5
-- | Generate transactions report items from a list of transactions, -- | Generate transactions report items from a list of transactions,
-- using the provided user-specified report query, a query specifying -- using the provided user-specified report query, a query specifying