how to use currency exchange with exchange_rate that is saved in ActiveRecords model?
laptopmutia opened this issue · 1 comments
laptopmutia commented
so I have a transaction model and in this Active Records model I have column that hold, currency buying_price
and selling_price
I want to use the exchange rates using this two column, is that possible?
because from the docs money
have a complicated exchange rates, it stores the exchange rates in a global/gem config instead per model
here is my schema
create_table "bills", force: :cascade do |t|
t.decimal "selling_currency_rate", default: "0.0", null: false
t.decimal "buying_currency_rate", default: "0.0", null: false
t.bigint "foreign_currency_id"
t.decimal "total_amount"
end
the default or local currency is always IDR
sunny commented
One way to get the current exchange rate could be to determine it on the spot. E.g.: 1.to_money("EUR") / 1.to_money("IDR")
.