hledger icon indicating copy to clipboard operation
hledger copied to clipboard

wish: hledger add should balance cost, not both entered commodities

Open simonmichael opened this issue 2 years ago • 1 comments

Discussed in #hledger today: when entering a stock sale with hledger add, including the cost basis with @ notation, if you leave the last amount blank, expecting hledger to calculate the capital gain/loss, instead it will balance the transaction with both amounts. Ie you end up with the not-so-useful:

2021-07-18 ZEC sale
    Assets:Wallet          -0.5 ZEC @ $60
    Assets:Cash                       $40
    Income:CapitalGains              $-40
    Income:CapitalGains     0.5 ZEC @ $60

rather than:

2021-07-18 ZEC sale
    Assets:Wallet          -0.5 ZEC @ $60
    Assets:Cash                       $40
    Income:CapitalGains              $-10

or (equivalently):

2021-07-18 ZEC sale
    Assets:Wallet          -0.5 ZEC @ $60
    Assets:Cash                       $40
    Income:CapitalGains               

When parsing this entry hledger normally converts to cost and infers a $-10 balancing amount for the last posting; we think hledger add should do the same.

simonmichael avatar Mar 10 '22 19:03 simonmichael

It might be useful for hledger add to check what the commonly-used commodity is for any particular account (so, using USD for Income:CapitalGains if USD is the most common commodity for that account).

There's a similar discussion going on for hledger-iadd: https://github.com/hpdeifel/hledger-iadd/issues/65#issuecomment-999817669

But then again, the two issues aren't fully equivalent. In this issue, it's a matter of explicit conversion, where cost is provided, and in the other, no cost is provided and so it is a question of whether an implicit conversion ought to be performed.

the-solipsist avatar Mar 18 '22 09:03 the-solipsist