Skip to content

feat: areg: Add --matching flag#2592

Open
alerque wants to merge 15 commits into
simonmichael:mainfrom
alerque:related-on-areg
Open

feat: areg: Add --matching flag#2592
alerque wants to merge 15 commits into
simonmichael:mainfrom
alerque:related-on-areg

Conversation

@alerque

@alerque alerque commented May 16, 2026

Copy link
Copy Markdown
Collaborator

Re-opening of #2541. Fixes #2540.

simonmichael and others added 15 commits April 1, 2026 23:18
…oday

Similar transactions were being date-weighted by their distance from
the journal's latest transaction date. This meant a future-dated
transaction, perhaps caused by a typo, could be greatly prioritised,
causing an unexpected choice of transaction to use for defaults.

Now, we date-weight by absolute distance (past or future) from today's date.
…r it

Port three Gain-related changes from hledger2 to improve compatibility
between hledger 1 and 2:

1. Don't infer Gain (G) type from account names; it must be declared
   explicitly with a type: tag.

2. Exclude Gain postings from transaction balancing.

3. Because Gain postings can be left amountless,
   always exclude amountless postings from reports.
This was backported recently from the hledger2 branch to better match
hledger 2's behaviour and allow easier interop on the same journal files.
Since then hledger 2 has switched to a better strategy.
So we can revert and pretend this never happened.

The Gain account type itself remains; and also some defensive changes
making reports ignore postings which have had no amount inferred for
them. This shouldn't happen any more with the Gain balancing exception
gone, but I have left those changes in, on the assumption that if it
arises again it's better to omit such postings than show a report with
broken layout.
U/UnrealisedGain is a subtype of Equity.
Like G/Gain, it's added here just to allow hledger 1.x to read hledger 2's journal files.

For this one, the type: tag will accept any of these spellings:
U, UnrealisedGain, UnrealizedGain.
Works like the inverse of the --related flag on register.
@simonmichael

Copy link
Copy Markdown
Owner

Could you rebase this against main when you get a chance.

@simonmichael

simonmichael commented Jun 11, 2026

Copy link
Copy Markdown
Owner

I like the result. I wonder how we can make the default and optional behaviours a bit more intuitive/consistent/easy to explain. I'm thinking also of the slightly complex behaviour described on #2540, and the slightly unintuitively named -r/--related flag (an option on register, the default mode on aregister).

Here are four modes (of the current PR) for us to contemplate:

$ hledger -f a.j areg expenses -w80
Transactions in Expenses and subaccounts:
2020-01-01 Vendor A             As:Account                $1005.00      $1005.00
2020-01-01 Vendor B             As:Account                $1005.00      $2010.00
$ hledger -f a.j areg expenses -w80 --matching
Transactions in Expenses and subaccounts:
2020-01-01 Vendor A             Ex:Foo, Ex:BankFee        $1005.00      $1005.00
2020-01-01 Vendor B             Ex:Bar, Ex:BankFee        $1005.00      $2010.00
$ hledger -f a.j areg expenses -w80 ba
Transactions in Expenses and subaccounts (matching query):
2020-01-01 Vendor A             Ex:BankFee                   $5.00         $5.00
2020-01-01 Vendor B             Ex:Bar, Ex:BankFee        $1005.00      $1010.00
$ hledger -f a.j areg expenses -w80 ba --matching
Transactions in Expenses and subaccounts (matching query):
2020-01-01 Vendor A             Ex:Foo, Ex:BankFee           $5.00         $5.00
2020-01-01 Vendor B             Ex:Bar, Ex:BankFee        $1005.00      $1010.00

@simonmichael

simonmichael commented Jun 11, 2026

Copy link
Copy Markdown
Owner

--matching and --related aren't immediately obvious as flags or antonyms. --related/-r came from Ledger, and we'll keep it for compatibility. But perhaps we should consider adding --show-matched and --show-other ?

@simonmichael simonmichael added needs-discussion To unblock: needs more discussion/review/exploration aregister needs-rebase To unblock: needs to be rebased against latest master branch labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aregister needs-discussion To unblock: needs more discussion/review/exploration needs-rebase To unblock: needs to be rebased against latest master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a flag for areg to show the queried account, not the *other* accounts

2 participants