Module: Aloe::AccountRepository

Included in:
Account
Defined in:
lib/aloe/account_repository.rb

Instance Method Summary collapse

Instance Method Details

#closedActiveRecord::Relation

Scope to closed accounts.

Returns:

  • (ActiveRecord::Relation)


20
21
22
# File 'lib/aloe/account_repository.rb', line 20

def closed
  unscoped.with_state('closed')
end

#currency(currency) ⇒ ActiveRecord::Relation

Scope by currency.

Parameters:

  • currency (String, Symbol)

    Currency symbol

Returns:

  • (ActiveRecord::Relation)


8
9
10
# File 'lib/aloe/account_repository.rb', line 8

def currency(currency)
  where(currency: currency)
end

#default_scopeObject

Default scope excludes closed accounts.



13
14
15
# File 'lib/aloe/account_repository.rb', line 13

def default_scope
  where('state != ?', 'closed')
end

#owner(owner) ⇒ ActiveRecord::Relation

Scope by owner.

Parameters:

  • owner (ActiveRecord::Base)

Returns:

  • (ActiveRecord::Relation)


28
29
30
# File 'lib/aloe/account_repository.rb', line 28

def owner(owner)
  where(owner_type: owner.class.model_name.to_s, owner_id: owner.id)
end

#trial_balance(currency) ⇒ Fixnum

Return the trial balance.

Trial balance is balance of all accounts in the system combined. It should at all times be 0. If it’s not, there is an error in accounts somewhere.

Parameters:

  • currency (String, Symbol)

    Currency symbol

Returns:

  • (Fixnum)

    Zero if everything’s fine



40
41
42
# File 'lib/aloe/account_repository.rb', line 40

def trial_balance(currency)
  currency(currency).sum :balance
end