hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Support alias subdirective for commodity

Open entropitor opened this issue 3 years ago • 5 comments

It would be nice if hledger supports the subdirectives of ledger-cli for the commodity directive

commodity $
   note American Dollars
   format $1,000.00
   nomarket
   alias USD
   default

Currently only format is recognized. And adding any other subdirective fails when using hledger. It would be nice if hledger allows these at least. In a first version, hledger could just ignore them and only later on implement them (Especially the alias one can be usefuly to be able to use $ and USD interchangeably).

entropitor avatar Dec 28 '21 16:12 entropitor

Thanks. I agree we should ignore Ledger subdirectives we don't support, probably in all directives, I think only account does that right now.

Could you analyse the commodity alias feature and try to list its use cases and interactions with other features ?

simonmichael avatar Dec 28 '21 16:12 simonmichael

As far as I can tell, whenever a commodity is used (either as argument on the CLI or in the ledger) it gets translated from the alias to the original commodity.

You cannot create an alias for a commodity that is used already. In the output, it always uses the "main" name. The main use case is to allow for e.g. € and EUR. € is not always as easy to type but a bit more clean in the ledger file. So having € in the ledger file is nice since it can be auto-generated etc. But when passing CLI arguments, it can be much faster to type EUR instead of €

entropitor avatar Dec 28 '21 22:12 entropitor

Thanks, that is clear so far. I think reasonably often people want to customise commodity symbols to something else for display. They might expect this directive to help with that; but I think it's a separate task and the two are independent.

simonmichael avatar Dec 28 '21 23:12 simonmichael

Actually, this would also help, you can use the following: (Imagining you want USD in the output and $ in your ledger)

commodity USD
  alias $

entropitor avatar Dec 29 '21 07:12 entropitor

This might also be of interest for those using --infer-equity.

For instance, I can imagine that people would want Equity:Conversion:EUR-USD:USD in account names, rather than Equity:Conversion:EUR-$:$. This might help achieve that.

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

having an alias for EUR (and others) would have been lovely 🙄

andycandy-dev avatar Feb 17 '23 21:02 andycandy-dev