From 56c38b1b29bd23bdd805e3828160ac7a73635c75 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 21 Feb 2023 10:04:07 -1000 Subject: [PATCH] fix: areg: handle an extra account query correctly (fix #2007) --- .../Reports/AccountTransactionsReport.hs | 8 +++- hledger/test/aregister.test | 37 +++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs index 2e227b8db..46d30f463 100644 --- a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs +++ b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs @@ -191,7 +191,13 @@ accountTransactionsReportItem reportq thisacctq signfn accttypefn bal (d, t) otheracctstr | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings | numotheraccts == 0 = summarisePostingAccounts thisacctps -- only postings to current account ? summarise those | otherwise = summarisePostingAccounts otheracctps -- summarise matched postings to other account(s) - amt = signfn . maNegate $ sumPostings thisacctps + -- 202302: Impact of t on thisacct - normally the sum of thisacctps, + -- but if they are null it probably means reportq is an account filter + -- and we should sum otheracctps instead. + -- This fixes hledger areg ACCT ACCT2 (#2007), hopefully it's correct in general. + amt + | null thisacctps = signfn $ sumPostings otheracctps + | otherwise = signfn . maNegate $ sumPostings thisacctps bal' = bal `maPlus` amt -- TODO needs checking, cf #1731 diff --git a/hledger/test/aregister.test b/hledger/test/aregister.test index 91761d092..cb9507cc3 100644 --- a/hledger/test/aregister.test +++ b/hledger/test/aregister.test @@ -12,36 +12,33 @@ Transactions in a and subaccounts: 2021-01-02 b 1 1 < -2021-01-01 - (a) 1 +2023-01-01 + assets:checking 1 + income:salary -1 -2021-01-02 - (a:aa) 10 - -2021-01-03 - (a:aa:aaa) 100 +2023-01-02 + assets:checking -2 + expenses:food 2 # 2. aregister ignores a depth limit, always showing transactions in subaccounts. #1448 -$ hledger -f- areg a depth:1 -Transactions in a and subaccounts: -2021-01-01 a 1 1 -2021-01-02 a:aa 10 11 -2021-01-03 a:aa:aaa 100 111 +$ hledger -f- areg checking depth:1 +Transactions in assets:checking and subaccounts: +2023-01-01 in:salary 1 1 +2023-01-02 ex:food -2 -1 #1634: # 3. aregister is always in historical mode, showing balance from prior transactions. -$ hledger -f- areg a -b 2021-01-02 -Transactions in a and subaccounts: -2021-01-02 a:aa 10 11 -2021-01-03 a:aa:aaa 100 111 +$ hledger -f- areg checking -b 2023-01-02 +Transactions in assets:checking and subaccounts: +2023-01-02 ex:food -2 -1 -# 4. Any additional arguments are a query filtering the transactions. +# 4. Any additional arguments are a query filtering the transactions. #2007 # This can cause the running balance to diverge from the real-world running balance. # For non-date/date2/depth queries, a hint is shown in the title. -$ hledger -f- areg a aaa -Transactions in a and subaccounts (matching query): -2021-01-03 a:aa:aaa 100 100 +$ hledger -f- areg checking expenses +Transactions in assets:checking and subaccounts (matching query): +2023-01-02 ex:food -2 -2 # 5. Sorts transactions first by transaction date (earliest date of the # matching postings) then by parse order. (#1642)