fix: areg: handle an extra account query correctly (fix #2007)

This commit is contained in:
Simon Michael 2023-02-21 10:04:07 -10:00
parent 44400e840c
commit 56c38b1b29
2 changed files with 24 additions and 21 deletions

View File

@ -191,7 +191,13 @@ accountTransactionsReportItem reportq thisacctq signfn accttypefn bal (d, t)
otheracctstr | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings otheracctstr | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings
| numotheraccts == 0 = summarisePostingAccounts thisacctps -- only postings to current account ? summarise those | numotheraccts == 0 = summarisePostingAccounts thisacctps -- only postings to current account ? summarise those
| otherwise = summarisePostingAccounts otheracctps -- summarise matched postings to other account(s) | 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 bal' = bal `maPlus` amt
-- TODO needs checking, cf #1731 -- TODO needs checking, cf #1731

View File

@ -12,36 +12,33 @@ Transactions in a and subaccounts:
2021-01-02 b 1 1 2021-01-02 b 1 1
< <
2021-01-01 2023-01-01
(a) 1 assets:checking 1
income:salary -1
2021-01-02 2023-01-02
(a:aa) 10 assets:checking -2
expenses:food 2
2021-01-03
(a:aa:aaa) 100
# 2. aregister ignores a depth limit, always showing transactions in subaccounts. #1448 # 2. aregister ignores a depth limit, always showing transactions in subaccounts. #1448
$ hledger -f- areg a depth:1 $ hledger -f- areg checking depth:1
Transactions in a and subaccounts: Transactions in assets:checking and subaccounts:
2021-01-01 a 1 1 2023-01-01 in:salary 1 1
2021-01-02 a:aa 10 11 2023-01-02 ex:food -2 -1
2021-01-03 a:aa:aaa 100 111
#1634: #1634:
# 3. aregister is always in historical mode, showing balance from prior transactions. # 3. aregister is always in historical mode, showing balance from prior transactions.
$ hledger -f- areg a -b 2021-01-02 $ hledger -f- areg checking -b 2023-01-02
Transactions in a and subaccounts: Transactions in assets:checking and subaccounts:
2021-01-02 a:aa 10 11 2023-01-02 ex:food -2 -1
2021-01-03 a:aa:aaa 100 111
# 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. # 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. # For non-date/date2/depth queries, a hint is shown in the title.
$ hledger -f- areg a aaa $ hledger -f- areg checking expenses
Transactions in a and subaccounts (matching query): Transactions in assets:checking and subaccounts (matching query):
2021-01-03 a:aa:aaa 100 100 2023-01-02 ex:food -2 -2
# 5. Sorts transactions first by transaction date (earliest date of the # 5. Sorts transactions first by transaction date (earliest date of the
# matching postings) then by parse order. (#1642) # matching postings) then by parse order. (#1642)