Module: ContactDisplay

Extended by:
ActiveSupport::Concern
Included in:
Contact
Defined in:
app/models/concerns/contact_display.rb

Overview

Display helpers, formatting, CRM links, and lookup methods for Contact.

See Also:

Instance Method Summary collapse

Instance Method Details

#all_addressesObject



59
60
61
62
63
64
# File 'app/models/concerns/contact_display.rb', line 59

def all_addresses
  addrs = []
  addrs.concat(addresses)
  addrs.concat(customer.all_addresses)
  addrs.uniq
end

#build_default_contact_points(required = nil) ⇒ Object

:reek:ControlParameter



66
67
68
69
70
71
# File 'app/models/concerns/contact_display.rb', line 66

def build_default_contact_points(required = nil) # :reek:ControlParameter
  %w[phone fax email].each do |cat|
    contact_points.build(category: cat, required: required == cat ? '1' : nil) if contact_points.none? { |cp| cp.category == cat }
  end
  self
end

#colleaguesObject



77
78
79
80
81
# File 'app/models/concerns/contact_display.rb', line 77

def colleagues
  return Contact.none unless customer

  customer.contacts.where.not(id:)
end

#countryObject



47
48
49
# File 'app/models/concerns/contact_display.rb', line 47

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

#first_addressObject



55
56
57
# File 'app/models/concerns/contact_display.rb', line 55

def first_address
  super || customer&.first_address
end

#guest?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/concerns/contact_display.rb', line 91

def guest?
  false
end

#last_invoice_shipping_costObject



17
18
19
# File 'app/models/concerns/contact_display.rb', line 17

def last_invoice_shipping_cost
  customer.nil? ? 0 : customer.last_invoice_shipping_cost
end

#localeObject



21
22
23
# File 'app/models/concerns/contact_display.rb', line 21

def locale
  customer&.locale || super
end

#main_addressObject



51
52
53
# File 'app/models/concerns/contact_display.rb', line 51

def main_address
  addresses.first || customer&.main_address
end

#open_activities_counterObject



73
74
75
# File 'app/models/concerns/contact_display.rb', line 73

def open_activities_counter
  all_activities.open_activities.visible_by_default.size
end

#options_for_reports_toObject



83
84
85
86
87
88
89
# File 'app/models/concerns/contact_display.rb', line 83

def options_for_reports_to
  res = customer || supplier
  return if res.nil?

  contacts = res.contacts.where(Contact[:id].not_eq(id.to_i)).order(:inactive).reverse_order
  contacts.map { |c| [(c.inactive? ? "#{c.full_name} (inactive)" : c.full_name), c.id] }
end

#reference_numberObject



29
30
31
# File 'app/models/concerns/contact_display.rb', line 29

def reference_number
  "CT#{id}"
end

#shipping_amount_last_30_daysObject



13
14
15
# File 'app/models/concerns/contact_display.rb', line 13

def shipping_amount_last_30_days
  customer.nil? ? 0 : customer.shipping_amount_last_30_days
end

#shipping_amount_last_monthObject



9
10
11
# File 'app/models/concerns/contact_display.rb', line 9

def shipping_amount_last_month
  customer.nil? ? 0 : customer.shipping_amount_last_month
end

#stateObject



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

def state
  inactive ? 'inactive' : 'active'
end

#supplier_contact?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/concerns/contact_display.rb', line 95

def supplier_contact?
  supplier.present?
end

#timezoneObject



43
44
45
# File 'app/models/concerns/contact_display.rb', line 43

def timezone
  ActiveSupport::TimeZone.find_tzinfo(timezone_name) || customer&.timezone
end

#to_labelObject



33
34
35
# File 'app/models/concerns/contact_display.rb', line 33

def to_label
  to_s
end

#to_sObject



37
38
39
40
41
# File 'app/models/concerns/contact_display.rb', line 37

def to_s
  label_parts = [full_name]
  label_parts << "#{customer.full_name} [#{customer.reference_number}]" if customer
  label_parts.join(' - ')
end