Class: PricingPlan

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pricing_plan.rb

Instance Method Summary collapse

Instance Method Details

#get_price(rule_ctx = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/pricing_plan.rb', line 10

def get_price( rule_ctx = nil ) 
      
  price = Price.new
  price.pricing_plan = self

  #first check if this is a simple amount if so get the amount.
  if self.is_simple_amount
    price.money = Money.new(:amount => self.money_amount, :currency => self.currency)

  #second check if a pricing calculation exists if so use it.
  elsif !self.pricing_calculation.nil?
    rule_ctx[:pricing_plan] = self
    rule_ctx[:price] = price
    eval(self.pricing_calculation)

  #finanlly if this is not a simple amount and has no pricing calcuation use the price components associated to this plan
  else
    self.pricing_plan_components.each do |pricing_plan_component|
      price_component = pricing_plan_component.get_price_component(rule_ctx)
      price.components << price_component
    end
  end

  price.description = self.description

  price
end