Sha256: f83c542142aa5f98608db29cb226f5c48ee0766ea74723b0b9d651eeaee43598

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

module Mks
  module Rate
    class ChargeableService < ApplicationRecord
      after_save :generate_bundle

      validates :code, :name, presence: true
      validates :code, uniqueness: { scope: :service_delivery_unit_id }

      belongs_to :service_type
      belongs_to :base_unit, class_name: 'UnitOfCharge'
      belongs_to :utilization_unit, class_name: 'UnitOfCharge', optional: true
      belongs_to :service_delivery_unit

      delegate(:name, to: :service_delivery_unit, prefix: true)
      delegate(:name, to: :base_unit, prefix: true)
      delegate(:name, to: :utilization_unit, prefix: true, allow_nil: true)
      delegate(:name, to: :service_type, prefix: true)

      def generate_bundle
        sb = ServiceBundle.create(code: code, name: name, percent_discount: 0,
                                  description: "Default bundle for service '#{name}'",
                                  service_delivery_unit_id: service_delivery_unit_id)
        sb.chargeable_services << self
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mks_rate-1.0.5 app/models/mks/rate/chargeable_service.rb
mks_rate-1.0.4 app/models/mks/rate/chargeable_service.rb
mks_rate-1.0.3 app/models/mks/rate/chargeable_service.rb
mks_rate-1.0.2 app/models/mks/rate/chargeable_service.rb
mks_rate-1.0.1 app/models/mks/rate/chargeable_service.rb