Sha256: 29b149d2c4019b544e2ef30dc6503edae61db3f9619175622b63505cdca63557

Contents?: true

Size: 927 Bytes

Versions: 13

Compression:

Stored size: 927 Bytes

Contents

#
# Encapulates a Cost and a Date, used to track costs by
# date so sums for date ranges can be generated.
#
class DatedCost < ActiveRecord::Base
  include E9Rails::ActiveRecord::Initialization
  include E9::ActiveRecord::TimeScopes

  money_columns :cost
  belongs_to :costable, :polymorphic => true
  validates :date, :date => true
  validates :cost, :numericality => true

  attr_accessor :temp_id

  def self.default_scope
    order('dated_costs.created_at ASC')
  end

  def as_json(options={})
    {}.tap do |hash|
      hash[:id]            = self.id
      hash[:cost]          = self.cost
      hash[:date]          = self.date
      hash[:costable_type] = self.costable_type.try(:underscore)
      hash[:costable_id]   = self.costable_id
      hash[:errors]        = self.errors

      hash.merge!(options)
    end
  end

  protected

    def _assign_initialization_defaults
      self.date ||= Date.today
    end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
e9_crm-0.1.34 app/models/dated_cost.rb
e9_crm-0.1.33 app/models/dated_cost.rb
e9_crm-0.1.32 app/models/dated_cost.rb
e9_crm-0.1.31 app/models/dated_cost.rb
e9_crm-0.1.30 app/models/dated_cost.rb
e9_crm-0.1.29 app/models/dated_cost.rb
e9_crm-0.1.28 app/models/dated_cost.rb
e9_crm-0.1.27 app/models/dated_cost.rb
e9_crm-0.1.26 app/models/dated_cost.rb
e9_crm-0.1.25 app/models/dated_cost.rb
e9_crm-0.1.24 app/models/dated_cost.rb
e9_crm-0.1.23 app/models/dated_cost.rb
e9_crm-0.1.22 app/models/dated_cost.rb