Sha256: 0420c3c9842de23d540fca3ad9c1cd1c7180b65a55b2426d2c6e49bdb810476a
Contents?: true
Size: 1.45 KB
Versions: 9
Compression:
Stored size: 1.45 KB
Contents
module Comee module Core class ClientPrice < Price enum :margin_type, {increase: 0, discount: 1} belongs_to :client belongs_to :previous_price, class_name: "Comee::Core::ClientPrice", optional: true belongs_to :next_price, class_name: "Comee::Core::ClientPrice", optional: true belongs_to :product_lookup, optional: true validates :price, :margin_type, presence: true validates :price, numericality: {greater_than: 0} validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100} validates :product_id, uniqueness: {scope: %i[client_id previous_price_id next_price_id status]} validate :validate_product_lookup def validate_product_lookup return unless product_lookup && product && client if product_lookup.itemable_id != client_id || product_lookup.itemable_type != "Comee::Core::Client" || product_lookup.product_id != product_id errors.add(:product_lookup, "contains wrong client or product.") end end def self.ransackable_attributes(_auth_object = nil) %w[ id valid_from valid_to price status product_id client_id previous_price_id next_price_id ] end def self.ransackable_associations(_auth_object = nil) %w[product client product_lookup] end end end end
Version data entries
9 entries across 9 versions & 1 rubygems