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 320 forks source link

Use exchange rates in reverse #2287

Open mvhulten opened 3 hours ago

mvhulten commented 3 hours ago

I have this exchange rate:

P 2024-11-18 19:00:00 EUR 11,664 NOK

but instead of using this to convert EUR from NOK, market values of transactions in the past are used when I run hledger balance MyAccount --value=now,EUR. I want that the above works as this:

P 2024-11-18 19:00:00 NOK 0,08573388 EUR

edit: I was hoping that --show-reverse would do that, but after realising that this is only used from the prices command (not for e.g. balance), I reworked this issue… which – I now realise – may be more of a support issue than a bug report (maybe it is a feature request).

I am running hledger 1.33 on OpenBSD.

simonmichael commented 3 hours ago

@mvhulten thanks - to save confusion, could you post a minimal repro when you have time ?

simonmichael commented 2 hours ago

PS I think it's this: an declared forward price, even an older one, is always preferred over an inferred reverse price (https://hledger.org/dev/hledger.html#finding-market-price). I think the workaround is simply to add more forward price declarations.

mvhulten commented 2 hours ago

In my MWE it works as I want and according to the documentation.

P 2023-01-01 16:00:00 EUR 10,0 NOK
P 2024-11-18 16:00:00 EUR 11,0 NOK

2024-01-14 * conversion
    EuroAccount     100,00 EUR @12,0 NOK
    KronerAccount

As expected, today's value of 11,0 NOK/EUR takes precedence. In my more complex multi-file ledger such a more recent declared price is ignored.

I will look into it better and find out where it fails.

simonmichael commented 1 hour ago

--debug 2 may be helpful.