special_price.rb 633 B

123456789101112131415161718192021222324252627
  1. class SpecialPrice < ActiveRecord::Base
  2. ##--- Llevar registro de Actividad del usuario
  3. audited
  4. belongs_to :product
  5. belongs_to :customer
  6. belongs_to :user
  7. has_many :pre_sales
  8. has_many :sales_details
  9. enum status: [ :erased, :active]
  10. validates_presence_of :product_id, message: "Debe seleccionar un producto.", :on => [:create, :update]
  11. validates_presence_of :customer_id, message: "Debe seleccionar un cliente.", :on => [:create, :update]
  12. scope :activos, -> { where( "status = 1") }
  13. def get_unit_discount(unit_price)
  14. if self.percent.present?
  15. (self.percent / 100) * unit_price
  16. else
  17. self.price
  18. end
  19. end
  20. end