Module: Models::CustomerOrganization
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer
- Defined in:
- app/concerns/models/customer_organization.rb
Overview
Parent/child orgs, buying groups, marketplace predicates, company determination.
Instance Method Summary collapse
-
#abbreviation_for_packing_list ⇒ String?
Short name used on packing lists for marketplace/retailer accounts.
-
#all_or_none_are_blank_in_address? ⇒ Boolean
Whether any core address fields are populated.
-
#amazon_com? ⇒ Boolean
Whether this customer is part of the Amazon.com ecosystem.
-
#amazon_seller_central? ⇒ Boolean
Whether this customer is an Amazon Seller Central account.
-
#amazon_vendor_central? ⇒ Boolean
Whether this customer is an Amazon Vendor Central account.
- #broadcast_buying_group_changed(buying_group_id_added: nil, buying_group_id_removed: nil) ⇒ void
-
#build_com? ⇒ Boolean
Whether this customer is the Build.com house account.
-
#buying_group_company? ⇒ Boolean
Whether this customer record represents a buying-group company.
-
#buying_group_name ⇒ String?
Name of the customer's buying group, if any.
-
#buying_groups_options_for_select ⇒ Array<Array(String, Integer)>
Options for a buying-group select control scoped to this customer.
-
#can_apply_document_customer?(document_customer_id, billing_customer_id = nil) ⇒ Boolean
Whether a document (invoice / credit memo) owned by +document_customer_id+ — optionally consolidated-billed to +billing_customer_id+ — may be applied to a receipt whose payor is this customer.
-
#canadian_tire? ⇒ Boolean
Whether this customer is the Canadian Tire house account.
-
#certified_installer? ⇒ Boolean
Whether this customer has any active installer certifications.
-
#company_name ⇒ String?
Organization name stored on the customer record.
- #company_name=(val) ⇒ void
-
#costco_ca? ⇒ Boolean
Whether this customer is the Costco Canada house account.
-
#customer_segment ⇒ String
One-letter segment code for this customer: TP (trade pro), BG (buying group), or HO (homeowner).
-
#dealer? ⇒ Boolean
Customer-level mirror of
Profile#dealer?. -
#dealer_or_trade_pro_for_locator? ⇒ Boolean
Legacy method kept for the dealer-locator call sites.
-
#determine_company_id ⇒ Integer?
Company ID for this customer, falling back to the customer's catalog.
-
#direct_buy? ⇒ Boolean?
Whether this customer is in a direct-buy buying group.
-
#direct_buy_can? ⇒ Boolean?
Whether this customer is in a Canada direct-buy buying group.
-
#direct_buy_usa? ⇒ Boolean?
Whether this customer is in a USA direct-buy buying group.
-
#e_commerce_misc? ⇒ Boolean?
Customer-level mirror of
Profile#e_commerce_misc?. -
#e_commerce_misc_or_direct_pro? ⇒ Boolean
Whether this customer has an e-commerce-misc or direct-pro profile.
-
#effective_report_grouping ⇒ String
Report grouping bucket assigned to this customer.
-
#home_depot_can? ⇒ Boolean
Whether this customer is the Home Depot Canada house account.
-
#home_depot_usa? ⇒ Boolean
Whether this customer is the Home Depot USA house account.
-
#homeowner? ⇒ Boolean
Whether this customer is a homeowner / end consumer.
-
#houzz? ⇒ Boolean
Whether this customer is the Houzz house account.
-
#include_po_prefix? ⇒ Boolean
Whether this customer's PO numbers should include a prefix.
-
#organization? ⇒ Boolean
Whether this customer is an organization (not a homeowner).
-
#organization_family_ids ⇒ Array<Integer>
Ids of the accounts whose credit memos may be applied to one another's receipts: this customer, its parent, and its direct children.
-
#overstock_com? ⇒ Boolean
Whether this customer is the Overstock.com house account.
-
#parent_organization_name ⇒ String?
Name of the customer's parent organization, if any.
-
#part_of_lowes_com? ⇒ Boolean
Whether this customer is the Lowe's.com house account.
-
#part_of_rona? ⇒ Boolean
Whether this customer belongs to the RONA organization family.
-
#person? ⇒ Boolean
Whether this customer represents a person (homeowner).
-
#retailer_organization? ⇒ Boolean
True for the marketplace/retailer house accounts (Amazon, Wayfair, Home Depot, Lowe's, Costco, …) whose orders belong to the retailer rather than the end consumer.
-
#same_organization_family?(other) ⇒ Boolean
Whether +other+ is in this customer's billing family — used to gate cross-account credit-memo application on receipts.
-
#self_and_children_ids ⇒ Array<Integer>
IDs of this customer and its direct child organizations.
-
#trade_pro? ⇒ Boolean
Customer-level mirrors of
Profile#trade_pro?/Profile#dealer?. - #update_buying_group(buying_group_id) ⇒ void
-
#use_parent_billing_address ⇒ Boolean
Whether this customer currently uses its parent organization's billing address.
- #use_parent_billing_address=(val) ⇒ void
-
#walmart_ca? ⇒ Boolean
Whether this customer is the Walmart Canada house account.
-
#wasn4_or_wat0f? ⇒ Boolean
Whether this customer is one of the WASN4 / WAT0F Vendor Central accounts.
-
#wayfair? ⇒ Boolean
Whether this customer is a Wayfair USA or Canada house account.
-
#wayfair_ca? ⇒ Boolean
Whether this customer is the Wayfair Canada house account.
-
#wayfair_usa? ⇒ Boolean
Whether this customer is the Wayfair USA house account.
-
#zoro? ⇒ Boolean
Whether this customer is the Zoro house account.
Instance Method Details
#abbreviation_for_packing_list ⇒ String?
Short name used on packing lists for marketplace/retailer accounts.
Prefers a known marketplace code when one applies, otherwise uses the
full name (when short enough) or an initialism.
87 88 89 90 91 |
# File 'app/concerns/models/customer_organization.rb', line 87 def abbreviation_for_packing_list abbreviation = name.length <= 18 ? name : nil abbreviation ||= name.split.filter_map(&:first).join marketplace_packing_abbreviation || abbreviation end |
#all_or_none_are_blank_in_address? ⇒ Boolean
Whether any core address fields are populated.
406 407 408 |
# File 'app/concerns/models/customer_organization.rb', line 406 def all_or_none_are_blank_in_address? zip.present? || street1.present? || street2.present? || street3.present? || city.present? end |
#amazon_com? ⇒ Boolean
Whether this customer is part of the Amazon.com ecosystem.
188 189 190 |
# File 'app/concerns/models/customer_organization.rb', line 188 def amazon_com? amazon_com_by_id? || amazon_com_by_parent_or_billing? || amazon_com_vendor_or_seller_ids? end |
#amazon_seller_central? ⇒ Boolean
Whether this customer is an Amazon Seller Central account.
195 196 197 |
# File 'app/concerns/models/customer_organization.rb', line 195 def amazon_seller_central? CustomerConstants::AMAZON_SELLER_CENTRAL_CUSTOMER_IDS.include?(id) end |
#amazon_vendor_central? ⇒ Boolean
Whether this customer is an Amazon Vendor Central account.
202 203 204 |
# File 'app/concerns/models/customer_organization.rb', line 202 def amazon_vendor_central? CustomerConstants::AMAZON_VENDOR_CENTRAL_CUSTOMER_IDS.include?(id) end |
#broadcast_buying_group_changed(buying_group_id_added: nil, buying_group_id_removed: nil) ⇒ void
This method returns an undefined value.
366 367 368 369 |
# File 'app/concerns/models/customer_organization.rb', line 366 def (buying_group_id_added: nil, buying_group_id_removed: nil) CustomerBuyingGroupUpdater.broadcast(self, added: , removed: ) end |
#build_com? ⇒ Boolean
Whether this customer is the Build.com house account.
272 273 274 |
# File 'app/concerns/models/customer_organization.rb', line 272 def build_com? id == CustomerConstants::BUILD_COM_ID end |
#buying_group_company? ⇒ Boolean
Whether this customer record represents a buying-group company.
318 319 320 |
# File 'app/concerns/models/customer_organization.rb', line 318 def profile&.name&.include?('Buying Group') && ! end |
#buying_group_name ⇒ String?
Name of the customer's buying group, if any.
70 71 72 |
# File 'app/concerns/models/customer_organization.rb', line 70 def &.name end |
#buying_groups_options_for_select ⇒ Array<Array(String, Integer)>
Options for a buying-group select control scoped to this customer.
63 64 65 |
# File 'app/concerns/models/customer_organization.rb', line 63 def BuyingGroup.(include_id: , company_id: determine_company_id) end |
#can_apply_document_customer?(document_customer_id, billing_customer_id = nil) ⇒ Boolean
Whether a document (invoice / credit memo) owned by +document_customer_id+
— optionally consolidated-billed to +billing_customer_id+ — may be applied
to a receipt whose payor is this customer. True when this customer is the
document's billing customer or in the same organization family. Single
source of truth behind the receipt form's mismatch-warning endpoints and
the XLSX import's customer gate, so both honor the same rule.
47 48 49 50 51 |
# File 'app/concerns/models/customer_organization.rb', line 47 def can_apply_document_customer?(document_customer_id, billing_customer_id = nil) return true if billing_customer_id.present? && billing_customer_id.to_i == id document_customer_id.present? && organization_family_ids.include?(document_customer_id.to_i) end |
#canadian_tire? ⇒ Boolean
Whether this customer is the Canadian Tire house account.
265 266 267 |
# File 'app/concerns/models/customer_organization.rb', line 265 def canadian_tire? id == CustomerConstants::CANADIAN_TIRE_ID end |
#certified_installer? ⇒ Boolean
Whether this customer has any active installer certifications.
286 287 288 |
# File 'app/concerns/models/customer_organization.rb', line 286 def certified_installer? certifications.active.any? end |
#company_name ⇒ String?
Organization name stored on the customer record.
110 111 112 |
# File 'app/concerns/models/customer_organization.rb', line 110 def company_name full_name if organization? end |
#company_name=(val) ⇒ void
This method returns an undefined value.
116 117 118 |
# File 'app/concerns/models/customer_organization.rb', line 116 def company_name=(val) self.full_name = val.presence end |
#costco_ca? ⇒ Boolean
Whether this customer is the Costco Canada house account.
216 217 218 |
# File 'app/concerns/models/customer_organization.rb', line 216 def costco_ca? id == CustomerConstants::COSTCO_CA_ID end |
#customer_segment ⇒ String
One-letter segment code for this customer: TP (trade pro), BG (buying group),
or HO (homeowner).
375 376 377 378 379 380 381 |
# File 'app/concerns/models/customer_organization.rb', line 375 def customer_segment if organization? .nil? ? 'TP' : 'BG' else 'HO' end end |
#dealer? ⇒ Boolean
Customer-level mirror of Profile#dealer?.
146 147 148 |
# File 'app/concerns/models/customer_organization.rb', line 146 def dealer? profile&.dealer? || false end |
#dealer_or_trade_pro_for_locator? ⇒ Boolean
Legacy method kept for the dealer-locator call sites. The _for_locator
suffix is now a misnomer — quote.rb also calls it — but the name is
preserved to avoid a cross-cutting rename in this PR. Implementation
now delegates to the new trade_pro? / dealer? predicates instead
of the deprecated profile.jde_code_1 attribute.
397 398 399 400 401 |
# File 'app/concerns/models/customer_organization.rb', line 397 def dealer_or_trade_pro_for_locator? trade_pro? || dealer? rescue StandardError false end |
#determine_company_id ⇒ Integer?
Company ID for this customer, falling back to the customer's catalog.
56 57 58 |
# File 'app/concerns/models/customer_organization.rb', line 56 def determine_company_id company_id || catalog&.company_id end |
#direct_buy? ⇒ Boolean?
Whether this customer is in a direct-buy buying group.
325 326 327 |
# File 'app/concerns/models/customer_organization.rb', line 325 def direct_buy? &.is_direct_buy? end |
#direct_buy_can? ⇒ Boolean?
Whether this customer is in a Canada direct-buy buying group.
339 340 341 |
# File 'app/concerns/models/customer_organization.rb', line 339 def direct_buy_can? &.is_direct_buy_can? end |
#direct_buy_usa? ⇒ Boolean?
Whether this customer is in a USA direct-buy buying group.
332 333 334 |
# File 'app/concerns/models/customer_organization.rb', line 332 def direct_buy_usa? &.is_direct_buy_usa? end |
#e_commerce_misc? ⇒ Boolean?
Customer-level mirror of Profile#e_commerce_misc?.
153 154 155 |
# File 'app/concerns/models/customer_organization.rb', line 153 def e_commerce_misc? profile&.e_commerce_misc? end |
#e_commerce_misc_or_direct_pro? ⇒ Boolean
Whether this customer has an e-commerce-misc or direct-pro profile.
160 161 162 |
# File 'app/concerns/models/customer_organization.rb', line 160 def e_commerce_misc_or_direct_pro? profile && (profile.e_commerce_misc? || profile.direct_pro?) end |
#effective_report_grouping ⇒ String
Report grouping bucket assigned to this customer.
103 104 105 |
# File 'app/concerns/models/customer_organization.rb', line 103 def effective_report_grouping Customer::ReportGrouping.get_report_grouping_for_customer(self) end |
#home_depot_can? ⇒ Boolean
Whether this customer is the Home Depot Canada house account.
174 175 176 |
# File 'app/concerns/models/customer_organization.rb', line 174 def home_depot_can? id == CustomerConstants::HOME_DEPOT_CAN_ID end |
#home_depot_usa? ⇒ Boolean
Whether this customer is the Home Depot USA house account.
167 168 169 |
# File 'app/concerns/models/customer_organization.rb', line 167 def home_depot_usa? id == CustomerConstants::HOME_DEPOT_USA_ID end |
#homeowner? ⇒ Boolean
Whether this customer is a homeowner / end consumer.
130 131 132 |
# File 'app/concerns/models/customer_organization.rb', line 130 def homeowner? profile_id == ProfileConstants::HOMEOWNER end |
#houzz? ⇒ Boolean
Whether this customer is the Houzz house account.
258 259 260 |
# File 'app/concerns/models/customer_organization.rb', line 258 def houzz? id == CustomerConstants::HOUZZ_ID end |
#include_po_prefix? ⇒ Boolean
Whether this customer's PO numbers should include a prefix.
96 97 98 |
# File 'app/concerns/models/customer_organization.rb', line 96 def include_po_prefix? CustomerConstants::SKIP_PREFIX_IN_PO_NUMBER_FOR_BILLING_ENTITY.exclude?(id) end |
#organization? ⇒ Boolean
Whether this customer is an organization (not a homeowner).
123 124 125 |
# File 'app/concerns/models/customer_organization.rb', line 123 def organization? !homeowner? end |
#organization_family_ids ⇒ Array<Integer>
Ids of the accounts whose credit memos may be applied to one
another's receipts: this customer, its parent, and its direct
children. Consolidated-billing parents and children share an AR
relationship, so a parent's receipt can offset a child's credit
memo and vice versa. Single-level hierarchy (parent_id) — no
grandchildren; siblings are reachable only through the shared parent.
24 25 26 |
# File 'app/concerns/models/customer_organization.rb', line 24 def organization_family_ids ([id, parent_id].compact + child_organizations.ids).uniq end |
#overstock_com? ⇒ Boolean
Whether this customer is the Overstock.com house account.
Matches by name, by known customer ID, or by catalog name.
295 296 297 298 299 |
# File 'app/concerns/models/customer_organization.rb', line 295 def overstock_com? name.to_s.casecmp('overstock.com').zero? || (id == 303_919) || catalog.name.to_s.casecmp('overstock.com').zero? end |
#parent_organization_name ⇒ String?
Name of the customer's parent organization, if any.
77 78 79 |
# File 'app/concerns/models/customer_organization.rb', line 77 def parent_organization_name parent_organization&.name end |
#part_of_lowes_com? ⇒ Boolean
Whether this customer is the Lowe's.com house account.
230 231 232 |
# File 'app/concerns/models/customer_organization.rb', line 230 def part_of_lowes_com? [CustomerConstants::LOWES_COM_ID].include?(id) end |
#part_of_rona? ⇒ Boolean
Whether this customer belongs to the RONA organization family.
223 224 225 |
# File 'app/concerns/models/customer_organization.rb', line 223 def part_of_rona? CustomerConstants::RONA_INC_CA_IDS.include?(id) end |
#person? ⇒ Boolean
Whether this customer represents a person (homeowner).
386 387 388 |
# File 'app/concerns/models/customer_organization.rb', line 386 def person? homeowner? end |
#retailer_organization? ⇒ Boolean
True for the marketplace/retailer house accounts (Amazon, Wayfair, Home
Depot, Lowe's, Costco, …) whose orders belong to the retailer rather
than the end consumer. Used by warranty registration to decide whether
an order's customer IS the registrant or a dedicated end-consumer
Customer must be attached instead.
308 309 310 311 312 313 |
# File 'app/concerns/models/customer_organization.rb', line 308 def retailer_organization? home_depot_usa? || home_depot_can? || walmart_ca? || amazon_com? || amazon_seller_central? || amazon_vendor_central? || costco_ca? || part_of_rona? || part_of_lowes_com? || wayfair? || houzz? || canadian_tire? || build_com? || zoro? || overstock_com? end |
#same_organization_family?(other) ⇒ Boolean
Whether +other+ is in this customer's billing family — used to gate
cross-account credit-memo application on receipts.
33 34 35 |
# File 'app/concerns/models/customer_organization.rb', line 33 def same_organization_family?(other) other.present? && organization_family_ids.include?(other.id) end |
#self_and_children_ids ⇒ Array<Integer>
IDs of this customer and its direct child organizations.
12 13 14 |
# File 'app/concerns/models/customer_organization.rb', line 12 def self_and_children_ids [id] + child_organizations.ids end |
#trade_pro? ⇒ Boolean
Customer-level mirrors of Profile#trade_pro? / Profile#dealer?.
Same delegation pattern as homeowner? (which reads profile_id).
Aliased to is_trade_pro? / is_dealer? in Models::CustomerAliases.
139 140 141 |
# File 'app/concerns/models/customer_organization.rb', line 139 def trade_pro? profile&.trade_pro? || false end |
#update_buying_group(buying_group_id) ⇒ void
This method returns an undefined value.
359 360 361 |
# File 'app/concerns/models/customer_organization.rb', line 359 def () CustomerBuyingGroupUpdater.call(self, ) end |
#use_parent_billing_address ⇒ Boolean
Whether this customer currently uses its parent organization's billing
address.
347 348 349 |
# File 'app/concerns/models/customer_organization.rb', line 347 def use_parent_billing_address parent_organization&.billing_address_id && (parent_organization.billing_address_id == billing_address_id) end |
#use_parent_billing_address=(val) ⇒ void
This method returns an undefined value.
353 354 355 |
# File 'app/concerns/models/customer_organization.rb', line 353 def use_parent_billing_address=(val) self.record_parent_billing_address = ((val == '1') && val.present?) end |
#walmart_ca? ⇒ Boolean
Whether this customer is the Walmart Canada house account.
181 182 183 |
# File 'app/concerns/models/customer_organization.rb', line 181 def walmart_ca? id == CustomerConstants::WALMART_CA_ID end |
#wasn4_or_wat0f? ⇒ Boolean
Whether this customer is one of the WASN4 / WAT0F Vendor Central accounts.
209 210 211 |
# File 'app/concerns/models/customer_organization.rb', line 209 def wasn4_or_wat0f? [CustomerConstants::AMAZON_VENDOR_CENTRAL_WASN4_CUSTOMER_ID, CustomerConstants::AMAZON_VENDOR_CENTRAL_WAT0F_CUSTOMER_ID].include?(id) end |
#wayfair? ⇒ Boolean
Whether this customer is a Wayfair USA or Canada house account.
237 238 239 |
# File 'app/concerns/models/customer_organization.rb', line 237 def wayfair? [CustomerConstants::WAYFAIR_USA_ID, CustomerConstants::WAYFAIR_CA_ID].include?(id) end |
#wayfair_ca? ⇒ Boolean
Whether this customer is the Wayfair Canada house account.
251 252 253 |
# File 'app/concerns/models/customer_organization.rb', line 251 def wayfair_ca? id == CustomerConstants::WAYFAIR_CA_ID end |
#wayfair_usa? ⇒ Boolean
Whether this customer is the Wayfair USA house account.
244 245 246 |
# File 'app/concerns/models/customer_organization.rb', line 244 def wayfair_usa? id == CustomerConstants::WAYFAIR_USA_ID end |
#zoro? ⇒ Boolean
Whether this customer is the Zoro house account.
279 280 281 |
# File 'app/concerns/models/customer_organization.rb', line 279 def zoro? id == CustomerConstants::ZORO_ID end |