ledger / vim-ledger

Vim plugin for Ledger
GNU General Public License v2.0
370 stars 56 forks source link

foldtext incorrectly takes balance assertions as txn value #153

Closed jmtd closed 4 months ago

jmtd commented 5 months ago

Given a transaction such as

2024-03-09 ebay payout
    assets:nationwide    £ 13.15 = £ 126.86
    io:income:ebay

the foldtext looks like

2024-03-09 ebay payout                                                   126.86

However, the correct amount for the transaction is £ 13.15 : £126.86 is balance assertion.

alerque commented 5 months ago

Contributions welcome.

I'm a little unsure about how you'd go about handling both regular transactions with incidental balance assertions and also dedicated balance assertion transactions, but if you come up with something I'm happy to facilitate things getting merged.

jmtd commented 5 months ago

I'm a little unsure about how you'd go about handling both regular transactions with incidental balance assertions and also dedicated balance assertion transactions,

Was my example an instance of the former? I don't think I've seen the latter. I'll have to check the docs (FWIW, I use hledger, so I will check the ledger docs/spec as well)

alerque commented 5 months ago

Yes your example is the former. An example of the latter in hledger would be to just assert the balance without actually moving anything between accounts. This is useful to add a reconcile point without tracking the balance on any actual transactions.

2024-03-09 Balance assertion check point
    (assets:nationwide)    == £ 126.86

Note that example uses the == syntax that indicates there are no other currencies in the account, but that isn't a unique identifying feature of these kind of transactions. They might just as well have = or even more than one posting.

2024-03-09 Balance assertion check point
    (assets:nationwide)    = £ 126.86
    (assets:nationwide)    =  $ 42.42
alerque commented 5 months ago

Perhaps the answer here is to always include the whole section after the account name and before any comments. This might include currency identifiers, amounts, balance assertions, and rates.

jmtd commented 5 months ago

Perhaps the answer here is to always include the whole section after the account name and before any comments. This might include currency identifiers, amounts, balance assertions, and rates.

I.e. (reusing my example)

2024-03-09 ebay payout                                     £ 13.15 = £ 126.86

?

I'm playing catch-up to understand the technical difficulty here (I haven't written much vimscript yet, and I'm only just reading vim-ledger's source as I type); I would have thought that modifying s:rx_amount would be sufficient to match the posting in the presence of an ad-hoc balance assertion, but is your point that, we probably want to show balance assertions (of both types) in folds? Thanks!

alerque commented 5 months ago

Yup, that was my thought.

I haven't looked at the code either, but rather than trying to parse for the amount it is probably going to be more robust to parse out the parts we know don't belong. We want everything after two spaces and before a comment marker (trimmed of course).

jmtd commented 5 months ago

I think, some people might want to see balance assertions in fold, but not everyone -- I wouldn't. So perhaps it should be optional. At the moment we don't show them at all (on purpose), so, personally I'd start with trying to fix-up the current foldtext to not include them, which means (I think) extending s:rx_amount to optionally match it.

But ouch vimscript regexps are hard work to grok :)

When it comes to displaying assertions, part of the issue is they're an assertion on one account, not the whole posting, and the foldtext doesn't include the accounts at all.

jmtd commented 5 months ago

For completion's sake, this is what the two forms of balance assertion transactions from https://github.com/ledger/vim-ledger/issues/153#issuecomment-1997491424 look like folded (after #154 ):

source

2024-02-29 balance assertion checkpoint
    (assets:monzo)    == £ 218.79

2024-02-29 balance assertion checkpoint 2
    (assets:monzo)    == £ 218.79
    (liabilities:amex)  == £ 0

result

2024-02-29 balance assertion checkpoint                                  218.79
2024-02-29 balance assertion checkpoint 2                                218.79

I think, by lucky coincidence, that's probably the best thing to do in the absence of any finer controls/preferences of how to display them.