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.01k stars 321 forks source link

Posting dates not displayed separately in hledger-web #1337

Open Nadrieril opened 4 years ago

Nadrieril commented 4 years ago

If I make a transaction with individual posting dates, like in this example from the ledger docs:

2008/10/16 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 37.50  ; date:2008/10/01
    Expenses:Food:Groceries           $ 37.50  ; date:2008/11/01
    Expenses:Food:Groceries           $ 37.50  ; date:2008/12/01
    Expenses:Food:Groceries           $ 37.50  ; date:2009/01/01
    Expenses:Food:Groceries           $ 37.50  ; date:2009/02/01
    Expenses:Food:Groceries           $ 37.50  ; date:2009/03/01
    Assets:Checking

and if I look in hledger-web for the transactions in Expenses:Food:Groceries, hledger-web will show a single entry for the whole transaction, dated 2008/10/01 (which is the smallest of the individual posting dates). I would have expected 6 different entries at the dates specified, like I see in the output of hledger register Expenses:Food:Groceries. The reason I think this is a bug and not a feature request is that posting dates are clearly taken into account (otherwise the transaction date would have been used), but weirdly.

Platform: NixOS Version: 1.18.1

simonmichael commented 4 years ago

Thanks for the report.

It's by design that the register in hledger-web (and hledger-ui) shows one line per transaction, to provide a simple UI that's more like other accounting apps, bank statements, etc.

In the general journal view, it shows the transaction date of course. In the account register view, it's supposed to show the date of posting to the account being viewed, for best accuracy. In this case in the Expenses:Food:Groceries register we have multiple posting dates, so what should it show ? Currently it picks the earliest posting date, as you say. (And when you hover over the transaction you can see all dates in the tooltip.)

That's not ideal, but seemed to me about equally useful in practice, and marginally more consistent (than switching to showing the transaction date). What do you think ?

simonmichael commented 4 years ago

The alternative is to implement and document: "Account registers show the date of posting to that account. Except, when a single transaction contains multiple such postings with different dates, the transaction date is shown."

Nadrieril commented 4 years ago

Thanks for your quick reply!

I see that I've been mixing postings and transactions in my head a bit. Indeed I don't want to see individual postings in hledger-web, that would be confusing. If there's only one posting date I think the current behavior is good.

When there are multiple posting dates though, I'd want to see one entry per date of posting to the account being viewed. But then I guess those entries would be neither individual postings nor individual transactions. Is there a way to make that work?

The idea I have is that in the account view, if a transaction has multiple postings to that account then they are displayed grouped by date. In the typical case, all postings have the same date so they are displayed as a single entry like they always have. Does that sound reasonable to you?

Given

2008/10/16 * Bountiful Blessings Farm
    Assets:Checking
    Assets:Cash                       $-20  ; date:2008/10/14
    Expenses:Food:Groceries           $ 10  ; date:2008/10/01
    Expenses:Food:Groceries           $ 10  ; date:2008/11/01
    Expenses:Food:Groceries           $ 10  ; date:2008/12/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
when listing Expenses:Food:Groceries, I expect to see Date To/From Amount
2008/10/01 Assets:Checking,Assets:Cash 10
2008/11/01 Assets:Checking,Assets:Cash 10
2008/12/01 Assets:Checking,Assets:Cash 10
2009/01/01 Assets:Checking,Assets:Cash 30
when listing Assets:Checking, I expect to see (that's the current behaviour) Date To/From Amount
2008/10/16 Expenses:Food:Groceries,Assets:Cash -40
when listing Assets, I expect to see (that's the current behaviour) Date To/From Amount
2008/10/16 Expenses:Food:Groceries -60
simonmichael commented 4 years ago

Thanks for the mockups. I think the conventional UI in other accounting apps is that registers are transaction-oriented, but you can optionally show/hide the postings ("splits"), either for an individual transaction or for all.

Nadrieril commented 4 years ago

I see. Do you know of accounting apps that support individual posting dates? I'd be curious to see how they solve this issue.

simonmichael commented 4 years ago

Not from memory, sorry..

Nadrieril commented 4 years ago

Would you in principle be ok with an option like hledger-web --split-individual-posting-dates that does what I suggested? I might look into implementing it

simonmichael commented 4 years ago

I'm not fully clear on what it would do, I'd be happy to try out your prototype if you make it.

Nadrieril commented 4 years ago

Cool thanks! Allow me to clarify what I mean: assume we are viewing Expenses:Food:Groceries in the web interface, and the journal contains the following transaction:

2008/10/16 * Bountiful Blessings Farm
    Assets:Checking
    Assets:Cash                       $-20  ; date:2008/10/14
    Expenses:Food:Groceries           $ 10  ; date:2008/10/01
    Expenses:Food:Groceries           $ 10  ; date:2008/11/01
    Expenses:Food:Groceries           $ 10  ; date:2008/12/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01

Currently, the code first filters the transaction and keeps only the relevant postings:

2008/10/16 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10  ; date:2008/10/01
    Expenses:Food:Groceries           $ 10  ; date:2008/11/01
    Expenses:Food:Groceries           $ 10  ; date:2008/12/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01

then it takes the earliest date from the relevant postings:

2008/10/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10
    Expenses:Food:Groceries           $ 10
    Expenses:Food:Groceries           $ 10
    Expenses:Food:Groceries           $ 15
    Expenses:Food:Groceries           $ 15

and finally displays the whole as a single entry:

2008/10/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 60

What I propose, is that when the --split-individual-posting-dates is enabled, the following happens instead. First we keep only the relevant postings like before:

2008/10/16 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10  ; date:2008/10/01
    Expenses:Food:Groceries           $ 10  ; date:2008/11/01
    Expenses:Food:Groceries           $ 10  ; date:2008/12/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01

now we do something different: we split the transaction into many subtransactions, one for each date present (most of the time this doesn't change anything because individual posting dates are uncommon)

2008/10/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10  ; date:2008/10/01
2008/11/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10  ; date:2008/11/01
2008/12/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10  ; date:2008/12/01
2009/01/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01
    Expenses:Food:Groceries           $ 15  ; date:2009/01/01

and finally we display one entry for each of those subtransactions:

2008/10/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10
2008/11/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10
2008/12/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 10
2009/01/01 * Bountiful Blessings Farm
    Expenses:Food:Groceries           $ 30

I investigated a bit, and it doesn't look very hard to implement. I think it would be enough to change this function: https://github.com/simonmichael/hledger/blob/4c3eaa5ffa451ec62d25d2229b2cbc8cecf1901f/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs#L85 so that between ts4 and ts5 it takes splits the transactions like I described. That should be sound because AccountTransactionsReportItem already supports transactions that carry only a relevant subset of their postings. The main uncertainty I have is how to add a new option and thread it to where I want to use it.

Btw, thanks for developing this insanely powerful tool!