class AvailableProduct < ActiveRecord::Base

  belongs_to :product
  belongs_to :pointsale

  has_many :categories, :through => :product

  audited

  validates :price_sale, :presence => { :message => "Debe especificar el precio de venta para su punto de venta"},  :numericality => { :message => "El precio debe ser mayor que el precio de venta base.", :greater_than => :get_price }, :on => :update_price
  scope :activos, -> { joins(:product).where( "products.status = 1").order("products.name") }

  protected

  def get_price
    product.price_sale
  end
end
