managing multiple currencies

22 views
Skip to first unread message

Tavis Ormandy

unread,
Apr 2, 2023, 11:42:22 AMApr 2
to ledge...@googlegroups.com
Hello! I sometimes spend money in two different currencies, $ and £.
This usually works fine, but it breaks a few reports. For example, now I
can't do this:

$ ledger reg --monthly -j ^Expenses:
While evaluating value expression:
quantity(scrub(display_amount))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
While converting $20.00
£15.00 to an amount:
While calling function 'quantity $20.00
£15.00':
Error: Cannot convert a balance with multiple commodities to an amount

That's fine, I'm happy converting it to $ so it's all the same commodity, so I did this:

P 2023/04/01 08:11:09 £ $1.2332433

And added --market, but that didn't help. The manual gave me the idea this might work:

commodity $
default

= expr commodity == "£"
; VALUE:: market(amount, date, exchange)

But that didn't help either.

Perhaps this is because ledger thinks £ is a currency and not a
commodity? Is there a way to force it to be a commodity?

Obviously I can just do ^Expenses: and expr "commodity == '$'", but then
I will have to make a different report for each currency!

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger tav...@sdf.org
_\_V _( ) _( ) @taviso

Tavis Ormandy

unread,
Apr 2, 2023, 2:06:17 PMApr 2
to ledge...@googlegroups.com
On 2023-04-02, Tavis Ormandy wrote:
> Hello! I sometimes spend money in two different currencies, $ and £.
> This usually works fine, but it breaks a few reports. For example, now I
> can't do this:
>
> $ ledger reg --monthly -j ^Expenses:
> While evaluating value expression:
> quantity(scrub(display_amount))
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> While converting $20.00
> £15.00 to an amount:
> While calling function 'quantity $20.00
> £15.00':
> Error: Cannot convert a balance with multiple commodities to an amount
>

Answering my own question, I think I was nearly there, you need:

= expr (account =~ /^Expenses:/ and commodity == '£')
; VALUE:: market(amount, date, exchange)

To lock the value in to the exchange rate on the date of the
transaction, and then add -X '$' to force the conversion.

If you don't want to automate it, you can also manually add something
like this to each transaction:

; VALUE:: $100

This seems (?) to give reasonable output, although I wonder if -X "$"
should just do this by default?
Reply all
Reply to author
Forward
0 new messages