-
-
Notifications
You must be signed in to change notification settings - Fork 332
Balance transactions more robustly and compatibly #2402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hmm, but while more robust in principle, the new balancing strategy can reject some entries that we previously accepted. I assume those will be easy to fix manually by making their decimals a little more correct. But it won't be ok to suddenly require people to do that. Perhaps we'll need to offer (or try) both behaviours ? |
This gets complicated, so I've written up my understanding of how
|
I have tested the new behaviour a little bit with my files. So far, I found only a few transactions per year which are now considered unbalanced, and it has been relatively easy to fix them manually (adding an expenses:rounding posting with no amount is one way). But I can see this being tricky/annoying for users after upgrading. I wonder if we need to keep the old behaviour, and maybe an improved transitional behaviour, perhaps something like this:
|
It's really cool but for compatibility. Maybe we should add a command line parameter to specify the global balancing strategy. This way users can force hledger to balance in a specific way We can also add a declarative syntax command to determine which balancing strategy should be used for each part in the journal syntax |
20ec9e9
to
93a88e0
Compare
Though breaking people's working journals is bad, creating more complications by trying to avoid that is also bad. So I've gone with a simpler toggle:
Here's the doc:
If you see any problems with this, let me know. |
To recap, the reason for changing things is to solve these problems:
|
And this might justify a version jump to 1.50, signalling the unusual breakage ("Unfortunately it can also reject some journal entries that worked with older hledger"); I don't know. |
And to recap more: the compatibility workaround I was contemplating was to offer a third option,
This would be a hybrid, primarily using the transaction precisions but if commodity directives specify a smaller display precision, using that instead. This would avoid breaking old journals, while also being better behaved than There'd be no point to |
From chat: Q: does that mean, with the old approach, accounts can theoretically accumulate tiny errors over time? A: that kind of error does not arise, at least because we always reconcile bank accounts. I guess typically it's the cost amount that's inexact, the data we are importing or entering will have a correct bank/fiat amount (and if not we'd notice) I guess I can check for this now with my own data.
(Show account balances, limited to depth 5, limited to the $ currency, overriding $'s display style to show 12 decimal places. Then filter that to show just the lines where there's a non-zero decimal digit in the 3rd place or beyond.) I do have a half cent balance in one asset account and one liability account, and in half a dozen expense accounts. Which is normally shown rounded to a cent. And I have a small 15 digit decimal balance in equity:starting balances (from lot starting balances getting multiplied by their costs, producing more decimals). So yes, with the old method I guess unaccounted-for remainders can accumulate, in accounts that (a) often have an inexact posting amount or cost amount and (b) are never reconciled - such as my equity, revenue, and expense accounts. |
Also, for release notes: Notably, the old behaviour could allow small remainders to accumulate over time, in accounts that (a) often have an inexact posting amount or cost amount and (b) are never reconciled (typically equity, revenues, and expenses). You can check for this more easily now, eg with a command like hledger bal cur:\\$ -c '$1.000000000000' | rg '\...0*[1-9]' (Show account balances, limited to the $ currency, overriding $'s display style to show 12 decimal places, and filter that to just the lines with a non-zero decimal digit in the 3rd place or beyond.)
#2402] (and drop the last sentence from the single-commodity unbalanced transaction error)
d2f4dfe
to
98eafc5
Compare
#2402] (and drop the last sentence from the single-commodity unbalanced transaction error)
Thanks for the comments; this has been merged, and included in the https://github.com/simonmichael/hledger/releases/tag/nightly binaries. |
Perfect. And you're right: in retrospect the original formulation with one was just as fine as the more verbose formulation! |
simonmichael#2402] (and drop the last sentence from the single-commodity unbalanced transaction error)
and add more tests.
When checking if a transaction is balanced, until now hledger has used a commodity's global display precision as its balancing precision. This turns out to be not ideal; one familiar annoyance is that increasing the display precision (eg using -c to show more decimals) can cause unbalanced transactions, making the journal unreadable. Another is that journals exported from Ledger or Beancount can be rejected as unbalanced by hledger, until commodity directives are added to help control the balancing precision.
This PR makes hledger use only the local transaction's precisions for balancing, like Ledger and Beancount. Ie, the precisions inferred from the (non-cost) amounts in the transaction being balanced. This nicely separates balancing and display, and makes us better at exchanging journal entries with Ledger and Beancount.
See also: