hpdeifel / hledger-iadd

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

Auto-suggest account-appropriate commodity balance rather than balance of all commodities #65

Open the-solipsist opened 2 years ago

the-solipsist commented 2 years ago

I structure my accounts such that different sub-accounts contain only a single commodity. So, for instance, Assets:Cash:INR and Assets:Cash:USD, and so on.

When I have a transaction with postings having multiple commodities (for instance, if I have a single transaction involving purchases in both INR and USD, the auto-suggested default amounts (i.e., the amounts if I simply press "Enter"/"Return") would be applied to a single account, whereas I would usually have two separate accounts to which they ought to be applied (i.e., Assets:Cash:INR and Assets:Cash:USD, rather then both the INR and USD balances from a single account).

If hledger-iadd could be smarter about which commodity to apply to which account (e.g., by checking if past transactions to that account only involve a single commodity), that would be very helpful. Currently, I have to manually enter the commodity and the amount instead of using the default auto-suggestions.

the-solipsist commented 2 years ago

As an example: Screenshot from 2021-12-22 22-33-26 Screenshot from 2021-12-22 22-35-10

In this example, I would want hledger-iadd to fill only the USD figure in Equity:Trading:Currency:INR-USD:USD, since that sub-account only ever has USD amounts, and then auto-suggest ₹-750.00 for a different 4th account.

hpdeifel commented 2 years ago

Hm, I wonder if this is common practice or if the behaviour that you suggest use would then in turn confuse other users that want to have both currencies suggested. Otherwise, it sounds reasonable to do.

the-solipsist commented 2 years ago

If a sub-account has a history of holding multiple currencies, then there's no issue at all. Those who would want both suggested would probably have a sub-account with multiple currencies (or zero currencies). But for those sub-accounts with only one currency, pressing "enter" once should use the appropriate one of the two/more currencies.

So if there's a fast programmatic way of determining if a sub-account has only one or multiple currencies, then that should be used. Or else, checking which currency was used the previous time with that sub-account.

Frankly, I would prefer that latter approach: automatically using the currency that was last associated with the sub-account.