mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 19:14:11 +00:00
* Add `AccountBalance` table for account views * Scaffold out account UI * Add D3 line chart scaffolding * Style fixes
21 lines
622 B
Ruby
21 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
|