hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Appending currency symbol in CSV import

Open ShrykeWindgrace opened this issue 6 months ago • 8 comments

Currently, when the field currency is set, the symbol get prepended, according to the current documentation currency field:

currency sets a currency symbol, to be prepended to all postings' amounts.
...

There's quite a list of currency symbols that are appended to the amount; e.g. Swiss francs or kronas in scandinavian countries.

It would be useful to have a field currencyAppend or some other name (I have a writer's black and can't find anything elegant) for such cases. One can also introduce currencyPrepend and make the now-active currency a synonym of the latter. Similarly for currencyN, of course.

ShrykeWindgrace avatar Sep 08 '25 10:09 ShrykeWindgrace

I agree that this is awkward sometimes. The usual workaround is to use a more elaborate amount assignment, like amount1 %amount_ %currency_ ..

simonmichael avatar Sep 08 '25 11:09 simonmichael

I agree that this is awkward sometimes. The usual workaround is to use a more elaborate amount assignment, like amount1 %amount_ %currency_ ..

That's what I do right now, that's indeed awkward.

ShrykeWindgrace avatar Sep 08 '25 11:09 ShrykeWindgrace

It would be a bit nonobvious, but: right now we detect and preserve a space after currency's value. We could say that if there's a space before it instead, we will add it on the right (with a space).

simonmichael avatar Sep 08 '25 11:09 simonmichael

It would be a bit nonobvious, but: right now we detect and preserve a space after currency's value. We could say that if there's a space before it instead, we will add it on the right (with a space).

So, the .csv.rules file will understand something like this?

currency " EUR"

ShrykeWindgrace avatar Sep 08 '25 11:09 ShrykeWindgrace

We don't require the quotes. So currently you can have

currency EUR

giving EUR123 or

currency EUR<SPACE>

giving EUR 123 and we could add support for

currency <SPACE>EUR

giving 123 EUR

simonmichael avatar Sep 08 '25 12:09 simonmichael

We don't require the quotes. So currently you can have

currency EUR

giving EUR123 or

currency EUR<SPACE>

Significant trailing whitespace, that's not something I expected, to be honest. I am more inclined to put quotes to highlight such cases=)

ShrykeWindgrace avatar Sep 08 '25 12:09 ShrykeWindgrace

I hear you. Eg currency EUR, currency "EUR ", currency " EUR".

We have had some significant whitespace from the beginning (2+ space delimiters in certain places; indentation for postings).

We don't use quotes for anything else in the rules file. Using them just for this would be an inconsistency.

We do use double quotes in journal files, to enclose complex commodity symbols and to give an empty value to commodity and payee directives.

simonmichael avatar Sep 08 '25 13:09 simonmichael

PS I would accept pull requests in this area. The only thing the above wouldn't allow is adding a currency symbol on the right with no separating space.

simonmichael avatar Sep 08 '25 13:09 simonmichael