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.66 app/models/comee/core/client.rb
comee_core-0.2.65 app/models/comee/core/client.rb
comee_core-0.2.64 app/models/comee/core/client.rb
comee_core-0.2.63 app/models/comee/core/client.rb
comee_core-0.2.62 app/models/comee/core/client.rb
comee_core-0.2.61 app/models/comee/core/client.rb
comee_core-0.2.60 app/models/comee/core/client.rb
comee_core-0.2.59 app/models/comee/core/client.rb
comee_core-0.2.58 app/models/comee/core/client.rb
comee_core-0.2.57 app/models/comee/core/client.rb
comee_core-0.2.56 app/models/comee/core/client.rb
comee_core-0.2.55 app/models/comee/core/client.rb
comee_core-0.2.54 app/models/comee/core/client.rb
comee_core-0.2.53 app/models/comee/core/client.rb
comee_core-0.2.52 app/models/comee/core/client.rb
comee_core-0.2.51 app/models/comee/core/client.rb
comee_core-0.2.50 app/models/comee/core/client.rb
comee_core-0.2.49 app/models/comee/core/client.rb
comee_core-0.2.48 app/models/comee/core/client.rb
comee_core-0.2.47 app/models/comee/core/client.rb