Repository navigation
feat: change: and balance: queries match reported amounts; amt: accepts a commodity symbol - #2847
Conversation
8270da8 to
833a148
Compare
|
Revised:
With |
The sum: query's plan (never committed), with a revision replacing sum: by two terms with fixed meanings: change: (an item's change) and balance: (its actual end balance), defined per kind of item matched rather than per command. Agreed decisions: real signed amounts, balance: fetching earlier postings, registers filtering after running totals, entries' balance: equal to change:. AI usage: Claude Opus 5.5/Fable 5.1, ~43k output tokens
…ounts
Two new query terms select report rows, or entries, by their summed
amounts, which amt: can't do since it tests individual postings:
change: by the row's change (the sum of its postings), balance: by its
balance at the end of its period. Eg:
hledger bal expenses change:'>100' # accounts which changed by more than 100
hledger bal assets balance:'<0' # accounts with a negative balance
hledger reg gifts -M change:'>100' # months with more than 100 in gifts
hledger areg checking balance:'<0' # transactions after which checking was overdrawn
hledger print not:change:0 # entries with a tolerated imbalance or unbalanced virtual postings
The comparison works like amt:'s, and N may have a commodity symbol
(change:'>$100', balance:'<0 EUR') to compare just that commodity.
Each term's meaning is fixed by the kind of item matched, not by the
command or its display options. balance: means the actual balance,
from the start of the journal, whether or not -H is used (a balance:
term makes bal include the earlier postings, and shows matched
accounts even if they had no postings in the period). Amounts are
tested with their real sign, as with amt:, not as displayed after
--invert or incomestatement's sign normalisation.
Balance reports test each account's own amounts, leaving out
non-matching accounts as an account query would, so parent balances,
totals and percentages include just the matching accounts. Budget
reports hide the non-matching rows. register tests postings or period
summaries and their running balance; aregister tests each
transaction's change and the balance after it; hidden rows still count
in running totals. print (and descriptions, notes, codes) tests each
entry's sum at cost, including unbalanced virtual postings, for both
terms. They can be combined with other terms only by AND, and work in
hledger-ui and hledger-web's search too.
Also, amt: can now include a commodity symbol, to compare only amounts
in that commodity: amt:'>$100', amt:'<200 EUR'. A posting with no
amount in that commodity doesn't match. This avoids cur: and its regex
escaping (cur:'\$' amt:'>100'). The amt: manual section is corrected:
it said postings with multi-commodity amounts always match, but they
match if any of their amounts does.
Internally, the terms are moved from the report query to a new
ReportSpec field, _rsRowQuery, which the reports apply after
aggregating; the posting and transaction matchers ignore them.
AI usage: Claude Fable 5.1/Fable 5.2/Opus 5.5, ~212k output tokens
833a148 to
6468b2d
Compare
Queries could match postings by amount (
amt:), but not accounts by their reported change or balance.This adds two query terms which test the calculated report items:
change:tests a row's change (the sum of its postings),balance:its balance at the end of its period.amt:(signed or magnitude). N may have a commodity symbol, egchange:'>$100'orbalance:'<0 EUR', to compare just that commodity.balance:is the actual balance from the start of the journal, whether or not-His used; it makesbalinclude the earlier postings, and matched accounts are shown even if they had no postings in the period. Amounts are tested with their real sign, asamt:does, not as displayed after--invertor bs/is sign normalisation.not:); inside OR, a negated group,any:orall:it's an error.amt:also accepts a commodity symbol now (amt:'>$100'), and theamt:docs are corrected: a multi-commodity posting matches if any of its amounts does.Internally, the terms are moved from the report query into a new
ReportSpecfield,_rsRowQuery, which reports apply after aggregating. The posting and transaction matchers ignore them.Docs: new "balance: and change: queries" section in the manual, and a line in hledger-web's search help (hledger.pot updated). Tests: hledger/test/query-balance-change.test (40 tests) and query-amt.test, plus unit tests and doctests in Hledger.Query.
The plan, with the revision from the original
sum:design and implementation notes: doc/PLAN-balance-change-queries.mdAI usage: Claude Fable 5.1/Opus 5.5, ~208k output tokens