mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
Multi-currency support (#425)
* Initial foundational pass at multi-currency * Default format currency * More work on currency and exchanging * Re-build currencies on change * Currency import/setup * Background job overhaul + cheaper OXR plan support * Lint fixes * Test fixes * Multi-currency setup instructions * Allow decimals in the balance field * Spacing fix for form --------- Signed-off-by: Josh Pigford <josh@joshpigford.com>
This commit is contained in:
parent
94f7b4ea8f
commit
aa351ae616
41 changed files with 634 additions and 176 deletions
28
lib/tasks/currencies.rake
Normal file
28
lib/tasks/currencies.rake
Normal file
|
@ -0,0 +1,28 @@
|
|||
namespace :currencies do
|
||||
desc "Seed Currencies"
|
||||
task seed: :environment do
|
||||
currencies = ENV["CURRENCIES"].split(",")
|
||||
|
||||
if currencies.count > 1 && ENV["OPEN_EXCHANGE_APP_ID"].present?
|
||||
url = "https://openexchangerates.org/api/currencies.json"
|
||||
|
||||
response = Faraday.get(url) do |req|
|
||||
req.params["app_id"] = ENV["OPEN_EXCHANGE_APP_ID"]
|
||||
end
|
||||
|
||||
oxr_currencies = JSON.parse(response.body)
|
||||
|
||||
currencies.each do |iso_code|
|
||||
Currency.find_or_create_by(iso_code: iso_code) do |c|
|
||||
c.name = oxr_currencies[iso_code]
|
||||
end
|
||||
end
|
||||
|
||||
puts "Currencies created: #{Currency.count}"
|
||||
elsif currencies.count == 1
|
||||
Currency.find_or_create_by(iso_code: currencies.first)
|
||||
else
|
||||
puts "No currencies found in ENV['CURRENCIES']"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue