Sha256: dee1586f48920523a95efcc1365305b9b03051e1f9e539d95c109ae6d04cb5eb

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

class OrderList < ActiveRecord::Base
  scope :not_ordered, where(:state => 'pending')

  has_many :orders, :dependent => :destroy
  has_many :purchase_requests, :through => :orders
  belongs_to :user, :validate => true
  belongs_to :bookstore, :validate => true
  has_many :subscriptions

  validates_presence_of :title, :user, :bookstore
  validates_associated :user, :bookstore

  state_machine :initial => :pending do
    before_transition :pending => :ordered, :do => :order

    event :sm_order do
      transition :pending => :ordered
    end
  end

  def self.per_page
    10
  end

  def total_price
    self.purchase_requests.sum(:price)
  end

  def order
    self.ordered_at = Time.zone.now
  end

  def ordered?
    true if self.ordered_at.present?
  end
end

# == Schema Information
#
# Table name: order_lists
#
#  id           :integer         not null, primary key
#  user_id      :integer         not null
#  bookstore_id :integer         not null
#  title        :text            not null
#  note         :text
#  ordered_at   :datetime
#  deleted_at   :datetime
#  state        :string(255)
#  created_at   :datetime
#  updated_at   :datetime
#

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enju_purchase_request-0.0.8 app/models/order_list.rb
enju_purchase_request-0.0.7 app/models/order_list.rb
enju_purchase_request-0.0.6 app/models/order_list.rb
enju_purchase_request-0.0.5 app/models/order_list.rb
enju_purchase_request-0.0.4 app/models/order_list.rb
enju_purchase_request-0.0.3 app/models/order_list.rb