module Mks module Rate class ChargeableServiceDiscount < ApplicationRecord validates :unit_variable, :from, :to, :value, :chargeable_service_id, presence: true validate :compare_from_and_to validate :check_for_negative_value belongs_to :chargeable_service private def compare_from_and_to if !from.nil? && !to.nil? if from > to errors.add(:from, 'The value of from can not exced the value of to') end end end def check_for_negative_value if !from.nil? && !to.nil? if from.negative? errors.add(:from, 'The value of from can not be less than zero') elsif to.negative? errors.add(:to, 'The value of to can not be less than zero') end end end end end end