ash_double_entry different currency
Working with USD and creating transfers from
AshPhoenix.Form.submit()
works as expected. I added additional accounts with a different currency, EUR, and this fails with:
which makes sense, but where did the :USD
come from if both accounts have :EUR
currencies?
I added some IO.inspects
to AshDoubleEntry.Transfer.Changes.VerifyTransfer
and the changeset comes in with :USD
Creating a transfer with :EUR
works from iex:
So where is an appropriate place to take our form_params.amount
and create an appropriate instance of Money
with the correct currency? Would it be in the App.Ledger.Transfer.create
code interface with a custom_input
or somewhere else?
6 Replies
🤔 what do the params look like going into the form?
You could do it by modifying the params in the form itself potentially
and that's from
AshPhoenix.Form.for_create(App.Ledger.Transfer, :create)
this is working, although I wonder if someplace in the domain/resource is better because this logic isn't applied to things like JSON or GraphQL APIs
Over those APIs I believe they accept an amount and a currency
That is pretty strange though, I think you could maybe do it as part of your template
like in the html include the currency and amount fields as nested fields
Which API's specifically? I'm still the newbie 👶
I mean
AshGraphql
and AshMoney
accept both a currency and an amount in their generated APIs
so they don't suffer from the same issue that your UI does where its just providing a number and so therefore using the default configured currencyah ok. I haven't turned on yet but good to know