Module: PartyIdentity
- Extended by:
- ActiveSupport::Concern
- Included in:
- Party
- Defined in:
- app/models/concerns/party_identity.rb
Overview
Name fields, display helpers, and type/role predicates for Party STI records.
== person? / organization? / homeowner? predicate resolution
The bare predicates defined here are the Party defaults. Customer and Contact
override them with subtly different semantics; pay attention when calling
them on a base Party versus the subclass:
- On Customer (CustomerOrganization):
person?==homeowner?
organization?==!homeowner? - On Contact:
person?always true
organization?==!homeowner?(delegated to its customer) - Note:
is_homeowner?/is_organization?defined on Contact delegate to the
contact's customer, while barehomeowner?/organization?use the
PartyIdentity definitions on the contact itself.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #admin? ⇒ Boolean
- #aka ⇒ Object
- #aka=(name) ⇒ Object
- #all_activities ⇒ Object
- #blog_admin? ⇒ Boolean
- #broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) ⇒ Object
- #can_be_certified? ⇒ Boolean
- #can_list_all_contact_resources? ⇒ Boolean
- #clear_individual_names ⇒ Object
- #clear_names ⇒ Object
- #contact? ⇒ Boolean (also: #is_contact?)
- #customer? ⇒ Boolean (also: #is_customer?)
- #determine_company_id ⇒ Object
- #direct_commercial? ⇒ Boolean (also: #is_direct_commercial?)
- #direct_pro? ⇒ Boolean (also: #is_direct_pro?)
- #employee? ⇒ Boolean (also: #is_employee?)
- #first_name ⇒ Object
- #first_name=(name) ⇒ Object
- #guest_individual_name? ⇒ Boolean (also: #has_guest_individual_name?)
- #guest_name? ⇒ Boolean (also: #has_guest_name?)
- #homeowner? ⇒ Boolean (also: #is_homeowner?)
- #id_and_name ⇒ Object
- #last_name ⇒ Object
- #last_name=(name) ⇒ Object
- #manager? ⇒ Boolean
- #middle_name ⇒ Object
- #middle_name=(name) ⇒ Object
- #name ⇒ Object
- #name=(name_to_use) ⇒ Object
- #organization? ⇒ Boolean (also: #is_organization?)
- #person? ⇒ Boolean (also: #is_person?)
- #primary_party ⇒ Object
-
#public_facing_full_name ⇒ Object
rubocop:enable Naming/VariableNumber.
- #public_facing_full_name=(name) ⇒ Object
- #show_name_four ⇒ Object (also: #show_name_4)
- #to_s ⇒ Object
- #update_product_interests(product_line_ids) ⇒ Object
Instance Method Details
#active? ⇒ Boolean
162 163 164 |
# File 'app/models/concerns/party_identity.rb', line 162 def active? !inactive? end |
#admin? ⇒ Boolean
154 155 156 |
# File 'app/models/concerns/party_identity.rb', line 154 def admin? account&.has_role?('admin') end |
#aka ⇒ Object
49 50 51 |
# File 'app/models/concerns/party_identity.rb', line 49 def aka name2 || '' end |
#aka=(name) ⇒ Object
53 54 55 |
# File 'app/models/concerns/party_identity.rb', line 53 def aka=(name) self.name2 = name unless person? end |
#all_activities ⇒ Object
201 202 203 |
# File 'app/models/concerns/party_identity.rb', line 201 def all_activities linked_activities end |
#blog_admin? ⇒ Boolean
166 167 168 |
# File 'app/models/concerns/party_identity.rb', line 166 def blog_admin? account&.has_role?('blog_admin') end |
#broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) ⇒ Object
219 220 221 222 |
# File 'app/models/concerns/party_identity.rb', line 219 def broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) PartyProductInterestSync.broadcast(self, added: product_line_ids_added, removed: product_line_ids_removed) end |
#can_be_certified? ⇒ Boolean
125 126 127 |
# File 'app/models/concerns/party_identity.rb', line 125 def can_be_certified? is_a?(Customer) || is_a?(Contact) || is_a?(Employee) end |
#can_list_all_contact_resources? ⇒ Boolean
170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/concerns/party_identity.rb', line 170 def can_list_all_contact_resources? if instance_of?(::Customer) || (instance_of?(::Contact) && account && (account.is_online_customer_administrator? || account.is_online_customer_sales_supervisor? || account.is_online_customer_accounting_supervisor?)) true else instance_of?(::Employee) end end |
#clear_individual_names ⇒ Object
80 81 82 83 84 |
# File 'app/models/concerns/party_identity.rb', line 80 def clear_individual_names self.name1 = nil self.name2 = nil self.name3 = nil end |
#clear_names ⇒ Object
73 74 75 76 77 78 |
# File 'app/models/concerns/party_identity.rb', line 73 def clear_names self.name1 = nil self.name2 = nil self.name3 = nil self.full_name = nil end |
#contact? ⇒ Boolean Also known as: is_contact?
134 135 136 |
# File 'app/models/concerns/party_identity.rb', line 134 def contact? instance_of? Contact end |
#customer? ⇒ Boolean Also known as: is_customer?
129 130 131 |
# File 'app/models/concerns/party_identity.rb', line 129 def customer? instance_of? Customer end |
#determine_company_id ⇒ Object
186 187 188 189 190 191 |
# File 'app/models/concerns/party_identity.rb', line 186 def determine_company_id resolved = customer&.determine_company_id if respond_to?(:customer) resolved ||= self[:company_id] resolved ||= Company::USA resolved end |
#direct_commercial? ⇒ Boolean Also known as: is_direct_commercial?
120 121 122 |
# File 'app/models/concerns/party_identity.rb', line 120 def direct_commercial? customer&.profile&.direct_commercial? end |
#direct_pro? ⇒ Boolean Also known as: is_direct_pro?
115 116 117 |
# File 'app/models/concerns/party_identity.rb', line 115 def direct_pro? customer&.profile&.direct_pro? end |
#employee? ⇒ Boolean Also known as: is_employee?
139 140 141 |
# File 'app/models/concerns/party_identity.rb', line 139 def employee? instance_of? Employee end |
#first_name ⇒ Object
25 26 27 |
# File 'app/models/concerns/party_identity.rb', line 25 def first_name name1 || '' end |
#first_name=(name) ⇒ Object
29 30 31 |
# File 'app/models/concerns/party_identity.rb', line 29 def first_name=(name) self.name1 = name.presence&.strip end |
#guest_individual_name? ⇒ Boolean Also known as: has_guest_individual_name?
210 211 212 |
# File 'app/models/concerns/party_identity.rb', line 210 def guest_individual_name? name1 =~ /^Guest / || name1 == 'Guest' end |
#guest_name? ⇒ Boolean Also known as: has_guest_name?
205 206 207 |
# File 'app/models/concerns/party_identity.rb', line 205 def guest_name? full_name =~ /^Guest / || full_name == 'Guest' end |
#homeowner? ⇒ Boolean Also known as: is_homeowner?
110 111 112 |
# File 'app/models/concerns/party_identity.rb', line 110 def homeowner? customer&.profile_id == ProfileConstants::HOMEOWNER end |
#id_and_name ⇒ Object
193 194 195 |
# File 'app/models/concerns/party_identity.rb', line 193 def id_and_name "#{id} #{full_name}" end |
#last_name ⇒ Object
41 42 43 |
# File 'app/models/concerns/party_identity.rb', line 41 def last_name name3 || '' end |
#last_name=(name) ⇒ Object
45 46 47 |
# File 'app/models/concerns/party_identity.rb', line 45 def last_name=(name) self.name3 = name.presence&.strip end |
#manager? ⇒ Boolean
158 159 160 |
# File 'app/models/concerns/party_identity.rb', line 158 def manager? account&.is_manager? end |
#middle_name ⇒ Object
33 34 35 |
# File 'app/models/concerns/party_identity.rb', line 33 def middle_name name2 || '' end |
#middle_name=(name) ⇒ Object
37 38 39 |
# File 'app/models/concerns/party_identity.rb', line 37 def middle_name=(name) self.name2 = name.presence&.strip end |
#name ⇒ Object
57 58 59 |
# File 'app/models/concerns/party_identity.rb', line 57 def name full_name || '' end |
#name=(name_to_use) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/party_identity.rb', line 61 def name=(name_to_use) logger.debug "Party#name called with #{name_to_use}" return if name_to_use.nil? || name_to_use.strip.empty? name_to_use&.strip! self.full_name = name_to_use return unless person? pnp = PersonNameParser.new name_to_use pnp.to_party(self) end |
#organization? ⇒ Boolean Also known as: is_organization?
149 150 151 |
# File 'app/models/concerns/party_identity.rb', line 149 def organization? !(homeowner? || employee?) end |
#person? ⇒ Boolean Also known as: is_person?
144 145 146 |
# File 'app/models/concerns/party_identity.rb', line 144 def person? contact? || employee? # not all parties have homeowner? defined end |
#primary_party ⇒ Object
182 183 184 |
# File 'app/models/concerns/party_identity.rb', line 182 def primary_party self end |
#public_facing_full_name ⇒ Object
rubocop:enable Naming/VariableNumber
96 97 98 99 100 |
# File 'app/models/concerns/party_identity.rb', line 96 def public_facing_full_name return nil if guest_individual_name? full_name end |
#public_facing_full_name=(name) ⇒ Object
102 103 104 105 106 107 108 |
# File 'app/models/concerns/party_identity.rb', line 102 def public_facing_full_name=(name) if name.present? self.name = name else clear_individual_names end end |
#show_name_four ⇒ Object Also known as: show_name_4
86 87 88 89 90 |
# File 'app/models/concerns/party_identity.rb', line 86 def show_name_four "#{first_name&.[](0)}#{last_name&.first(3)}".upcase rescue StandardError '' end |
#to_s ⇒ Object
197 198 199 |
# File 'app/models/concerns/party_identity.rb', line 197 def to_s full_name end |
#update_product_interests(product_line_ids) ⇒ Object
215 216 217 |
# File 'app/models/concerns/party_identity.rb', line 215 def update_product_interests(product_line_ids) PartyProductInterestSync.call(self, product_line_ids) end |