hpdeifel / hledger-iadd

A terminal UI as drop-in replacement for hledger add.
BSD 3-Clause "New" or "Revised" License
77 stars 8 forks source link

Auto-suggested default remainder amount is sometimes incorrect #63

Closed the-solipsist closed 2 years ago

the-solipsist commented 2 years ago

Sometimes the default auto-suggestion for the remainder amount to balance a transaction is incorrect. I can't see a pattern as to when or why this happens, so can't really reproduce it.

Here's what it looks like: Screenshot from 2021-12-19 19-12-30

Notice the (₹-100.00) instead of the expected (₹-25.00)

the-solipsist commented 2 years ago

Sometimes, instead of an incorrect auto-suggested default, instead there is no auto-suggested default.

For instance: Screenshot from 2021-11-21 03-07-26

hpdeifel commented 2 years ago

When iadd detects that the currently entered transaction is an exact part of an older transaction, it keeps suggesting amounts from the older transaction. So in the first example, it could be that there's an older transaction where you also bought food for ₹25 at cafe da costa, but also other stuff for ₹75.

As for the second example, iadd only suggests an empty amount when the transaction is currently balanced. It checks this via hledgers built-in function isTransactionBalanced and it seems that the latter considers anything smaller than the display precision to be 0. @simonmichael, should I use something else?

simonmichael commented 2 years ago

I'm not sure what's going on, but maybe compare with hledger add as a reference ?

hpdeifel commented 2 years ago

I'm not sure what's going on, but maybe compare with hledger add as a reference ?

hledger considers transactions balanced if the difference in amounts is smaller than the display precision. E.g. the following:

2021-12-22 Test
    a    0,000000000000000000000000000000000000000000001€

This is inconvenient for iadd users who want to actually balance the transaction but iadd thinks it already is.

the-solipsist commented 2 years ago

What exactly is the "display precision"? In a file included in my default journal, I have the following directive: commodity XLM 100,000.0000001

simonmichael commented 2 years ago

Display precision is the number of decimal places inferred or configured to use for displaying a commodity - 7 for XLM in your example.

@hpdeifel, does the issue arise in hledger add as well ? I'm assuming not, so maybe you could do whatever it does ?

the-solipsist commented 2 years ago

Tested on hledger-add, and that works as expected:

Screenshot from 2021-12-23 01-50-18

Interestingly, unlike hledger-iadd, hledger-add suggests the appropriate commodity symbol. So if I press \<tab>, I can auto-fill XLM 0.0000001 and then \<backspace> twice, and change that to XLM 0.0000025.

hpdeifel commented 2 years ago

Indeed, I'll take a look at hledger add

hpdeifel commented 2 years ago

I've fixed the bug with empty amounts in commit 4eec0f80a510f16dc036b27a60089077909a2fe2.

@the-solipsist Your first point about non-empty but non-balancing amounts should be the intended behavior that I described in https://github.com/hpdeifel/hledger-iadd/issues/63#issuecomment-999714111. Can you confirm that that's actually what you're seeing?

the-solipsist commented 2 years ago

Hi. Yes, I can confirm that it has taken the ₹-100.00 from a previous transaction, and I think this is reasonable behaviour. I'm closing this issue. Thanks for the fix in https://github.com/hpdeifel/hledger-iadd/commit/4eec0f80a510f16dc036b27a60089077909a2fe2.