Module: Models::CustomerDisplay

Extended by:
ActiveSupport::Concern
Included in:
Customer
Defined in:
app/concerns/models/customer_display.rb

Overview

Display, formatting, CRM links, locale, and select-option helpers for Customer.

See Also:

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.affiliations_for_selectArray<String>

Affiliation choices for select dropdowns.

Returns:

  • (Array<String>)

    the list of customer affiliations



18
19
20
# File 'app/concerns/models/customer_display.rb', line 18

def affiliations_for_select
  CustomerConstants::AFFILIATIONS
end

.customer_is_real?(customer) ⇒ Boolean

Whether the customer is a real customer rather than the website's own walk-in account.

Parameters:

  • customer (Customer, nil)

    the customer to check

Returns:

  • (Boolean)

    true when the customer has an account whose login is not 'www_warmlyyours_com'



34
35
36
37
38
# File 'app/concerns/models/customer_display.rb', line 34

def customer_is_real?(customer)
  return false unless customer&.

  customer.. != 'www_warmlyyours_com'
end

.options_for_terms_selectArray<String>

Payment-term choices for select dropdowns.

Returns:

  • (Array<String>)

    the available payment terms



44
45
46
47
# File 'app/concerns/models/customer_display.rb', line 44

def options_for_terms_select
  [Customer::TERM_DUE, Customer::TERM_NET15, Customer::TERM_NET30,
   Customer::TERM_NET37, Customer::TERM_NET45, Customer::TERM_NET60, Customer::TERM_NET90]
end

.select_number_of_officesArray<Array(String, String)>

Number-of-offices range choices for select dropdowns.

Returns:

  • (Array<Array(String, String)>)

    label/value pairs including an 'Unknown' option



60
61
62
# File 'app/concerns/models/customer_display.rb', line 60

def select_number_of_offices
  [%w[Unknown unknown]] + CustomerConstants::NUMBER_OF_OFFICES.map { |range| [range, range] }
end

.select_projectsArray<Array(String, String)>

Projects-per-year range choices for select dropdowns.

Returns:

  • (Array<Array(String, String)>)

    label/value pairs including an 'Unknown' option



53
54
55
# File 'app/concerns/models/customer_display.rb', line 53

def select_projects
  [%w[Unknown unknown]] + CustomerConstants::PROJECTS_PER_YEAR.map { |range| [range, range] }
end

.states_for_selectArray<Array(String, String)>

Customer state choices as label/value pairs for select dropdowns.

Returns:

  • (Array<Array(String, String)>)

    pairs of human state name and state value



25
26
27
# File 'app/concerns/models/customer_display.rb', line 25

def states_for_select
  state_machines[:state].states.map { |sm_state| [sm_state.human_name, sm_state.value] }
end

Instance Method Details

#billing_address_attributesHash?

Attributes of the customer's billing address, if any.

Returns:

  • (Hash, nil)

    the billing address attributes, or nil when there is no billing address



117
118
119
120
121
# File 'app/concerns/models/customer_display.rb', line 117

def billing_address_attributes
  billing_address.attributes
rescue StandardError
  nil
end

#companyObject

Alias for Catalog#company

Returns:

  • (Object)

    Catalog#company

See Also:



10
# File 'app/concerns/models/customer_display.rb', line 10

delegate :company, to: :catalog

#countryString?

The customer's country, falling back to the country of their catalog's store.

Returns:

  • (String, nil)

    the country code



82
83
84
# File 'app/concerns/models/customer_display.rb', line 82

def country
  super || catalog&.store&.country
end

#customer_service_managerObject

Alias for Catalog#customer_service_manager

Returns:

  • (Object)

    Catalog#customer_service_manager

See Also:



11
# File 'app/concerns/models/customer_display.rb', line 11

delegate :customer_service_manager, to: :catalog

#localeString, ...

The customer's locale, derived from their catalog when available.

Returns:

  • (String, Symbol, nil)

    the locale for the customer's catalog, or the default locale



75
76
77
# File 'app/concerns/models/customer_display.rb', line 75

def locale
  Catalog.catalog_id_to_locale(catalog_id) || super
end

#main_addressAddress?

The customer's preferred address: mailing, then shipping, then billing, then the default.

Returns:

  • (Address, nil)

    the first available address



68
69
70
# File 'app/concerns/models/customer_display.rb', line 68

def main_address
  mailing_address || shipping_address || billing_address || super
end

#online?Boolean

Whether the customer can log in online.

Returns:

  • (Boolean)

    true when the customer has an associated account



103
104
105
# File 'app/concerns/models/customer_display.rb', line 103

def online?
  .present?
end

#product_review_delay_monthsInteger

Number of months to wait before requesting a product review from this customer.

Returns:

  • (Integer)

    the delay in months, shorter for homeowners than for trade professionals



126
127
128
129
130
131
132
# File 'app/concerns/models/customer_display.rb', line 126

def product_review_delay_months
  if homeowner?
    Customer::HOMEOWNER_PRODUCT_REVIEW_DELAY_MONTHS
  else
    Customer::TRADE_PRO_PRODUCT_REVIEW_DELAY_MONTHS
  end
end

#reference_numberString

The customer's reference number.

Returns:

  • (String)

    the id prefixed with 'CN', e.g. "CN123"



110
111
112
# File 'app/concerns/models/customer_display.rb', line 110

def reference_number
  "CN#{id}"
end

#to_labelString

Label for select dropdowns and pickers.

Returns:

  • (String)

    reference number followed by the full name, e.g. "[CN123] Jane Doe"



96
97
98
# File 'app/concerns/models/customer_display.rb', line 96

def to_label
  "[CN#{id}] #{full_name}"
end

#to_sString

Human-readable identifier for the customer.

Returns:

  • (String)

    full name followed by the reference number, e.g. "Jane Doe [CN123]"



89
90
91
# File 'app/concerns/models/customer_display.rb', line 89

def to_s
  "#{full_name} [CN#{id}]"
end