2024-02-02 09:05:04 -06:00
|
|
|
class Account < ApplicationRecord
|
|
|
|
belongs_to :family
|
2024-02-02 11:09:31 -06:00
|
|
|
|
2024-02-09 14:26:54 +00:00
|
|
|
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
|
2024-02-02 23:06:29 +00:00
|
|
|
|
2024-02-03 15:38:52 -05:00
|
|
|
delegate :type_name, to: :accountable
|
2024-02-06 12:30:51 -05:00
|
|
|
|
2024-02-10 16:18:56 -06:00
|
|
|
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
|