mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
* Add `AccountBalance` table for account views * Scaffold out account UI * Add D3 line chart scaffolding * Style fixes
20 lines
622 B
Ruby
20 lines
622 B
Ruby
class Account < ApplicationRecord
|
|
belongs_to :family
|
|
has_many :account_balances
|
|
|
|
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
|
|
|
|
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
|
|
end
|