hledger
hledger copied to clipboard
Setting display order of parent accounts requires declaring them
I'm using hledger 1.26 on Ubuntu 22.04.
I have a ledger file which looks like this:
account expenses:b
account assets:a
2021-01-01
assets:a 10
expenses:b -10
Now if I run hledger balance, I get this output:
$ hledger balance
10 assets:a
-10 expenses:b
--------------------
0
I was expecting expenses:b to be listed before assets:a, in order to match the declaration order.
After doing some digging, it turns out that I can adjust the order I expect by adding these account lines:
account expenses
account assets
account expenses:b
account assets:a
commodity 1000.00
2021-01-01
assets:a 10
expenses:b -10
Now hledger balance shows the expected output:
$ hledger balance
-10 expenses:b
10 assets:a
--------------------
0
However, it's not ideal to have to add account expenses and account assets. I don't want to allow any postings on these parent accounts, (only the sub-accounts), and I was relying on hledger's strict mode to detect any accidental postings there. By adding account expenses and account assets, I'm now allowing postings in these parent accounts, just in order to get the declaration order I'm looking for.
This is functioning as documented (https://hledger.org/hledger.html#account-display-order) and discussed (#1218), but you're right, to fully control display order you must sometimes declare a parent account which then also permits postings to itself. #1218 is still open, we don't yet have a proposal that solves this.
A possible workaround:
https://hledger.org/scripts.html#hledger-check-postable - check that no postings are made to accounts declared with a postable:n or postable:no tag