simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
3.05k stars 321 forks source link

implement ledger's register --related-all (show all postings of matched transactions, in a register-style report) #994

Open mildred opened 5 years ago

mildred commented 5 years ago

It would be nice to be able to see all account names on transaction on register subcommand. The web interface already shows transactions like that, having the same format on the CLI would be nice.

This can be specially useful when you want to locate transactions matching on the complete assets hierarchy, and you want to know on which assets subaccount the transaction is about, and which other accounts the transaction is about.

simonmichael commented 5 years ago

Do you mean like hledger-web's account register, http://demo.hledger.org/register?q=inacct%3AAssets%3AChecking ? You know about reg -r, I guess ?

mildred commented 5 years ago

Well, not exactly, this is what does --related.

Here, I'd want to see the full transaction with all postings in it.

For example, with the following journal file:

2019-01-01 Test
  assetsa:checking
  expenses:test  10

2019-01-01 Test
  assets:cash
  expenses:test  20

2019-01-01 Foo
  elsewhere
  expenses:foo  30

If I want to track assets and see complete transaction, with ledger r --related-all assetsI get:

19-Jan-01 Test            assetsa:checking        -10       -10
                          expenses:test            10         0
19-Jan-01 Test            assets:cash             -20       -20
                          expenses:test            20         0

(that's what I would like to see)

But with hledger r assets I only get:

2019/01/01 Test         as:checking           -10           -10
2019/01/01 Test         assets:cash           -20           -30

and hledger r --related assets shows me the other side:

2019/01/01 Test         ex:test                10            10
2019/01/01 Test         ex:test                20            30

But there is no way to see both.

simonmichael commented 5 years ago

Thanks for the example. I didn't know about ledger register --related-all. What about using hledger print [-x] ?

simonmichael commented 5 years ago

Or hledger print assets | hledger -f- register

mildred commented 5 years ago

It does seem to work, yes. I don't know if it can create quirks in display as it filters transactions, and I can imagine some total balance being wring on the display.

However having a nicer way to display this would be nice without needing unix pipes.

Perhaps having a way to configure aliases could solve this without introducing a new flag. I can see aliases being useful to generate the same reports

simonmichael commented 5 years ago

I think the piped command above should be exactly equivalent to --related-all, or close enough that we'll never notice the difference.

It should be an easy feature to add, but I hesitate to invite a PR since I haven't yet really seen the real-world need for this particular kind of report. [More examples welcome.]

mildred commented 5 years ago

real world usage is mostly that I uses register to view all transactions filtered by some account (for example transactions made in cash, or transaction made with the checking account). Then, I read through them all and I need to get all accounts of a particular transaction to fully understand them (especially when there is more than 2 accounts per transaction).

Also, seeing everything in a transaction seems more logical to me. I don't see the use of --related if it does not behaves like --related-all.

I'll try to monitor my usage and come back with more specific use cases

simonmichael commented 5 years ago

I have that need too, but doesn’t print cover that ?

mildred commented 5 years ago

Print does not show accounts as nicely with colors and in columns...

simonmichael commented 5 years ago

I would merge a PR for this..

ony commented 5 years ago

I was missing this feature also. But I was imaging something like query prefix txn:SOME-QUERY which in result will filter postings in a same way as hledger print SOME-QUERY. And my main usage was to get balance view of transactions involving specific asset/income account.

ony commented 5 years ago

I'm not sure why I didn't mentioned it earlier. Maybe I didn't read comments that closely.

Print does not show accounts as nicely with colors and in columns...

I guess you can use sometime popular trick of inheriting superb filter functionality of print via piping its output through hledger again. For example ledger r --related-all assets can look like:

hledger print assets | hledger -f- -I reg

Note that -I (ignore assertions) is important since you most likely filtering something out which may lead to different numbers in accumulated balances.

simonmichael commented 5 years ago

I mentioned this above, though you're right to advise using -I as well. "Print does not show accounts as nicely with colors and in columns" was mildred's response to that.

mildred commented 4 years ago

Well, it's not just formatting. I am not sure that because some transactions are filtered out, I might miss some information about some account, and I may end up with incorrect numbers. The simple fact that it might be needed to ignore assertions does not look good to me.

And the accumulated balances is important to me. I'm mostly using the register command to get a view similar to what I can see on my bank account so I can reconcile the two and make sure everything is correct.

simonmichael commented 4 years ago

Hello again! For generating the report you gave above, we have some options:

  1. hledger print assets | hledger -I -f- reg

    Exactly equivalent to ledger reg --related-all assets I believe, so no need to worry about missing information or incorrect numbers. Works today.

  2. hledger reg txn:assets

    ony's idea; also equivalent to the above. txn: is a new query that would work with any command. print txn:ACCT would be equivalent to just print ACCT. Adds just a little more complexity to the query language.

  3. hledger reg --related-all assets

    Add a Ledger-style --related-all flag to the register* commands only.

And the accumulated balances is important to me. I'm mostly using the register command to get a view similar to what I can see on my bank account so I can reconcile the two and make sure everything is correct.

There's no difficulty here, I do it all the time. For this you need to run register or hledger-ui --register on the bank account (only).