Sha256: 67c8e7a02163110d43ce8a56fa180e73e5bdddb89d61ac74484d080a8e78a6db

Contents?: true

Size: 979 Bytes

Versions: 35

Compression:

Stored size: 979 Bytes

Contents

module Comee
  module Core
    class Client < ApplicationRecord
      before_save -> { self.subsidiary = !parent.nil? }

      belongs_to :user, optional: true
      belongs_to :parent, class_name: "Comee::Core::Client", optional: true
      belongs_to :currency, optional: true
      has_and_belongs_to_many :contacts, join_table: :comee_core_clients_contacts
      has_and_belongs_to_many :agents, join_table: :comee_core_clients_agents
      has_many :client_warehouses

      validates :code, :name, :address, :locale, presence: true
      validates :code, uniqueness: true

      delegate(:name, to: :user, prefix: true, allow_nil: true)

      def self.ransackable_attributes(_auth_object = nil)
        %w[
          id
          user_id
          address
          code
          name
          locale
          parent_id
          subsidiary
        ]
      end

      def self.ransackable_associations(_auth_object = nil)
        ["parent"]
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
comee_core-0.2.46 app/models/comee/core/client.rb
comee_core-0.2.45 app/models/comee/core/client.rb
comee_core-0.2.44 app/models/comee/core/client.rb
comee_core-0.2.43 app/models/comee/core/client.rb
comee_core-0.2.42 app/models/comee/core/client.rb
comee_core-0.2.41 app/models/comee/core/client.rb
comee_core-0.2.40 app/models/comee/core/client.rb
comee_core-0.2.39 app/models/comee/core/client.rb
comee_core-0.2.38 app/models/comee/core/client.rb
comee_core-0.2.37 app/models/comee/core/client.rb
comee_core-0.2.36 app/models/comee/core/client.rb
comee_core-0.2.35 app/models/comee/core/client.rb
comee_core-0.2.34 app/models/comee/core/client.rb
comee_core-0.2.33 app/models/comee/core/client.rb
comee_core-0.2.32 app/models/comee/core/client.rb