cirandas.net

ref: master

plugins/currency/lib/ext/enterprise.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require_dependency 'enterprise'

class Enterprise

  has_many :enterprise_currencies, -> { includes(:currency).order('id ASC') },
    class_name: 'CurrencyPlugin::EnterpriseCurrency'

  has_many :accepted_currencies, -> {
    where('currency_plugin_enterprise_currencies.is_organizer <> ?', true).order('id ASC')
  }, through: :enterprise_currencies, source: :currency

  has_many :organized_currencies, -> {
    where('currency_plugin_enterprise_currencies.is_organizer = ?', true).order('id ASC')
  }, through: :enterprise_currencies, source: :currency

  has_many :currencies, -> { order('id ASC') }, through: :enterprise_currencies, source: :currency

  def currencies_with_environment_default
    self.currencies_without_environment_default + [self.environment.default_currency]
  end
  alias_method_chain :currencies, :environment_default

  def other_currencies
    self.environment.currencies - self.currencies
  end

end