1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 14:19:39 +02:00
Maybe/app/models/account.rb

20 lines
593 B
Ruby
Raw Normal View History

2024-02-02 09:05:04 -06:00
class Account < ApplicationRecord
belongs_to :family
2024-02-02 11:09:31 -06:00
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
2024-02-02 23:06:29 +00:00
delegate :type_name, to: :accountable
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
2024-02-02 09:05:04 -06:00
end