<commit_before>class Product < ActiveRecord::Base

  belongs_to :facility
  belongs_to :initial_order_status, :class_name => 'OrderStatus', :foreign_key => 'initial_order_status_id'
  belongs_to :facility_account
  has_many   :product_users
  has_many   :order_details
  has_many   :file_uploads

  validates_presence_of :name, :type
  validate_url_name :url_name
  validates_inclusion_of :requires_approval, :is_archived, :is_hidden, :in => [true, false, 0, 1]
  
  named_scope :active,             :conditions => { :is_archived => false, :is_hidden => false }
  named_scope :active_plus_hidden, :conditions => { :is_archived => false}
  named_scope :archived,           :conditions => { :is_archived => true }
  named_scope :not_archived,       :conditions => { :is_archived => false }
  
  def initial_order_status
    self[:initial_order_status] or OrderStatus.default_order_status
  end

  def current_price_policies
    current_policies = {}
    PricePolicy.find(:all, :conditions => ["start_date <= ? AND #{self.class.name.downcase}_id = ?", Time.zone.now, self.id]).each { |pp|
      unless current_policies[pp.price_group_id].nil?
        current_policies[pp.price_group_id] = pp if pp.start_date > current_policies[pp.price_group_id].start_date
      else
        current_policies[pp.price_group_id] = pp
      end
    }
    current_policies.values
  end

  def <=> (obj)
    name.casecmp obj.name
  end
  
  def parameterize
    self.class.to_s.parameterize.to_s.pluralize<commit_msg>Task #30441: #current_price_policies should consider expire_date<commit_after>class Product < ActiveRecord::Base

  belongs_to :facility
  belongs_to :initial_order_status, :class_name => 'OrderStatus', :foreign_key => 'initial_order_status_id'
  belongs_to :facility_account
  has_many   :product_users
  has_many   :order_details
  has_many   :file_uploads

  validates_presence_of :name, :type
  validate_url_name :url_name
  validates_inclusion_of :requires_approval, :is_archived, :is_hidden, :in => [true, false, 0, 1]
  
  named_scope :active,             :conditions => { :is_archived => false, :is_hidden => false }
  named_scope :active_plus_hidden, :conditions => { :is_archived => false}
  named_scope :archived,           :conditions => { :is_archived => true }
  named_scope :not_archived,       :conditions => { :is_archived => false }
  
  def initial_order_status
    self[:initial_order_status] or OrderStatus.default_order_status
  end

  def current_price_policies
    current_policies = {}
    PricePolicy.find(:all, :conditions => ["#{self.class.name.downcase}_id = ? AND start_date <= ? AND expire_date > ?", self.id, Time.zone.now, Time.zone.now]).each { |pp|
      unless current_policies[pp.price_group_id].nil?
        current_policies[pp.price_group_id] = pp if pp.start_date > current_policies[pp.price_group_id].start_date
      else
        current_policies[pp.price_group_id] = pp
      end
    }
    current_policies.values
  end

  def <=> (obj)
    name.casecmp obj.name
  end
  
  def parameterize
    self.class.to_s.parameterize.to_s.pluralize
{'fraction_non_alphanumeric': 0.10533159947984395, 'fraction_numerical': 0.002925877763328999, 'mean_word_length': 4.052545155993432, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1031655', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1050, 'n_words': 193}