1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 23:59:40 +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:
Josh Pigford 2024-02-10 16:18:56 -06:00 committed by GitHub
parent 94f7b4ea8f
commit aa351ae616
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 634 additions and 176 deletions

View file

@ -5,5 +5,15 @@ class Account < ApplicationRecord
delegate :type_name, to: :accountable
monetize :balance_cents
before_create :check_currency
def check_currency
if self.original_currency == self.family.currency
self.converted_balance = self.original_balance
self.converted_currency = self.original_currency
else
self.converted_balance = ExchangeRate.convert(self.original_currency, self.family.currency, self.original_balance)
self.converted_currency = self.family.currency
end
end
end

2
app/models/currency.rb Normal file
View file

@ -0,0 +1,2 @@
class Currency < ApplicationRecord
end

View file

@ -0,0 +1,6 @@
class ExchangeRate < ApplicationRecord
def self.convert(from, to, amount)
rate = ExchangeRate.find_by(base_currency: from, converted_currency: to)
amount * rate.rate
end
end