Module: Valuation::LifetimeValue
- Extended by:
- ActiveSupport::Concern
- Included in:
- Organization, Person
- Defined in:
- app/models/valuation/lifetime_value.rb
Overview
Anything with a :lifetime_value column and has_many orders can use this module.
Instance Method Summary collapse
-
#calculate_lifetime_value ⇒ Object
Calculate the lifetime value of this model by summing the price of all items attached to orders attached to this person.
-
#lifetime_orders ⇒ Object
Includers can define a method called lifetime_orders which will override this method.
Instance Method Details
#calculate_lifetime_value ⇒ Object
Calculate the lifetime value of this model by summing the price of all items attached to orders attached to this person. Save the value in lifetime_value. Return the value
24 25 26 27 28 |
# File 'app/models/valuation/lifetime_value.rb', line 24 def calculate_lifetime_value self.lifetime_value = Item.where(:order_id => self.lifetime_orders).sum(Item.total_price_sql_sum).to_i self.save(:validate => false) self.lifetime_value end |
#lifetime_orders ⇒ Object
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
15 16 17 |
# File 'app/models/valuation/lifetime_value.rb', line 15 def lifetime_orders orders end |