Sha256: 58f11b02c3bacbc62834bc53ddb4fc291c369c917df97af1bb40d107462f7e42
Contents?: true
Size: 1.68 KB
Versions: 9
Compression:
Stored size: 1.68 KB
Contents
module Logistics module Core class ServiceDeliveryUnit < ApplicationRecord validates :code, :name, presence: true, uniqueness: true validates :currency_id, :service_delivery_unit_type_id, presence: true belongs_to :currency belongs_to :service_delivery_unit_type has_and_belongs_to_many :chargeable_services, class_name: 'Logistics::Core::ChargeableService', join_table: 'logistics_core_service_delivery_unit_chargeable_services' has_many :children, class_name: 'ServiceDeliveryUnit', foreign_key: 'parent_id' belongs_to :parent, class_name: 'ServiceDeliveryUnit', optional: true def self.build(options = {}) ServiceDeliveryUnit.new(options) end def get_sdus_by_code(code) sdu_type = ServiceDeliveryUnitType.get_sdu_type_by_code(code) sdus = ServiceDeliveryUnit.where(service_delivery_unit_type_id: sdu_type.id) sdus = change_to_hash(sdus) return sdus end def to_json JSON.parse( Jbuilder.encode do |json| json.id self.id json.code self.code json.name self.name json.currency_id self.currency_id json.currency_name self.currency.name json.address self.address json.service_delivery_unit_type_id self.service_delivery_unit_type_id json.service_delivery_unit_type_name self.service_delivery_unit_type.name json.parent_id self.parent_id end ) end def change_to_hash(items) data = [] items.each { |item| data.push item.to_json } return data end end end end
Version data entries
9 entries across 9 versions & 1 rubygems