Class: Comee::Core::ClientAddress

Inherits:
Address show all
Defined in:
app/models/comee/core/client_address.rb

Constant Summary

Constants inherited from Address

Address::ADDRESS_TYPES, Address::BASIC_ADDRESS, Address::DELIVERY_ADDRESS, Address::INVOICING_ADDRESS, Address::SHIPPING_ADDRESS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_attributes(_auth_object = nil) ⇒ Object



25
26
27
# File 'app/models/comee/core/client_address.rb', line 25

def self.ransackable_attributes(_auth_object = nil)
  %w[name address_type email state]
end

Instance Method Details

#validate_defaultObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/comee/core/client_address.rb', line 10

def validate_default
  return unless client && address_type && default

  default_count = if new_record?
                    ClientAddress.where(address_type: address_type, client: client, default: true).count
                  else
                    ClientAddress.where(address_type: address_type, client: client, default: true)
                                 .where.not(id: id).count
                  end

  return if default_count.zero?

  errors.add(:default, "cannot be set to true. There is already a default address for this client and address type.")
end