Module: Valuation::LifetimeFees

Extended by:
ActiveSupport::Concern
Included in:
Organization
Defined in:
app/models/valuation/lifetime_fees.rb

Overview

Anything with a :lifetime_fees column and has_many orders can use this module.

Instance Method Summary collapse

Instance Method Details

#calculate_lifetime_feesObject

Calculate the lifetime fees of this model by summing the price of all items attached to orders attached to this model. Save the value in lifetime_fees. Return the value



34
35
36
37
38
# File 'app/models/valuation/lifetime_fees.rb', line 34

def calculate_lifetime_fees
  self.lifetime_fees = Organization.where(:id => self.id).joins(:orders => :items).sum('items.service_fee').to_i
  self.save(:validate => false)
  self.lifetime_fees
end

#lifetime_ordersObject

Includers can define a method called lifetime_orders which will override this method.

lifetime_orders should return the orders that this model wants to include in the calculation



25
26
27
# File 'app/models/valuation/lifetime_fees.rb', line 25

def lifetime_orders
  orders
end