Module: CustomerOrganization

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

Overview

Parent/child orgs, buying groups, marketplace predicates, company determination.

See Also:

Instance Method Summary collapse

Instance Method Details

#abbreviation_for_packing_listObject



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

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

Returns:

  • (Boolean)


249
250
251
# File 'app/models/concerns/customer_organization.rb', line 249

def all_or_none_are_blank_in_address?
  zip.present? || street1.present? || street2.present? || street3.present? || city.present?
end

#amazon_com?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/concerns/customer_organization.rb', line 127

def amazon_com?
  amazon_com_by_id? || amazon_com_by_parent_or_billing? || amazon_com_vendor_or_seller_ids?
end

#amazon_seller_central?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/models/concerns/customer_organization.rb', line 131

def amazon_seller_central?
  CustomerConstants::AMAZON_SELLER_CENTRAL_CUSTOMER_IDS.include?(id)
end

#amazon_vendor_central?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/models/concerns/customer_organization.rb', line 135

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) ⇒ Object



221
222
223
224
# File 'app/models/concerns/customer_organization.rb', line 221

def broadcast_buying_group_changed(buying_group_id_added: nil,
                                   buying_group_id_removed: nil)
  CustomerBuyingGroupUpdater.broadcast(self, added: buying_group_id_added, removed: buying_group_id_removed)
end

#build_com?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'app/models/concerns/customer_organization.rb', line 175

def build_com?
  id == CustomerConstants::BUILD_COM_ID
end

#buying_group_company?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'app/models/concerns/customer_organization.rb', line 193

def buying_group_company?
  profile&.name&.include?('Buying Group') && !buying_group
end

#buying_group_nameObject



58
59
60
# File 'app/models/concerns/customer_organization.rb', line 58

def buying_group_name
  buying_group&.name
end

#buying_groups_options_for_selectObject



54
55
56
# File 'app/models/concerns/customer_organization.rb', line 54

def buying_groups_options_for_select
  BuyingGroup.options_for_select(include_id: buying_group_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.

Parameters:

  • document_customer_id (Integer, String, nil)

    the document's customer_id

  • billing_customer_id (Integer, String, nil) (defaults to: nil)

    the document's billing_customer_id

Returns:

  • (Boolean)


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

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

Returns:

  • (Boolean)


171
172
173
# File 'app/models/concerns/customer_organization.rb', line 171

def canadian_tire?
  id == CustomerConstants::CANADIAN_TIRE_ID
end

#certified_installer?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'app/models/concerns/customer_organization.rb', line 183

def certified_installer?
  certifications.active.any?
end

#company_nameObject



80
81
82
# File 'app/models/concerns/customer_organization.rb', line 80

def company_name
  full_name if organization?
end

#company_name=(val) ⇒ Object



84
85
86
# File 'app/models/concerns/customer_organization.rb', line 84

def company_name=(val)
  self.full_name = val.presence
end

#costco_ca?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'app/models/concerns/customer_organization.rb', line 143

def costco_ca?
  id == CustomerConstants::COSTCO_CA_ID
end

#customer_segmentObject



226
227
228
229
230
231
232
# File 'app/models/concerns/customer_organization.rb', line 226

def customer_segment
  if organization?
    buying_group.nil? ? 'TP' : 'BG'
  else
    'HO'
  end
end

#dealer?Boolean

Returns:

  • (Boolean)


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

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.

Returns:

  • (Boolean)


243
244
245
246
247
# File 'app/models/concerns/customer_organization.rb', line 243

def dealer_or_trade_pro_for_locator?
  trade_pro? || dealer?
rescue StandardError
  false
end

#determine_company_idObject



50
51
52
# File 'app/models/concerns/customer_organization.rb', line 50

def determine_company_id
  company_id || catalog&.company_id
end

#direct_buy?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'app/models/concerns/customer_organization.rb', line 197

def direct_buy?
  buying_group&.is_direct_buy?
end

#direct_buy_can?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'app/models/concerns/customer_organization.rb', line 205

def direct_buy_can?
  buying_group&.is_direct_buy_can?
end

#direct_buy_usa?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'app/models/concerns/customer_organization.rb', line 201

def direct_buy_usa?
  buying_group&.is_direct_buy_usa?
end

#e_commerce_misc?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/concerns/customer_organization.rb', line 107

def e_commerce_misc?
  profile&.e_commerce_misc?
end

#e_commerce_misc_or_direct_pro?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/concerns/customer_organization.rb', line 111

def e_commerce_misc_or_direct_pro?
  profile && (profile.e_commerce_misc? || profile.direct_pro?)
end

#effective_report_groupingObject



76
77
78
# File 'app/models/concerns/customer_organization.rb', line 76

def effective_report_grouping
  Customer::ReportGrouping.get_report_grouping_for_customer(self)
end

#home_depot_can?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/models/concerns/customer_organization.rb', line 119

def home_depot_can?
  id == CustomerConstants::HOME_DEPOT_CAN_ID
end

#home_depot_usa?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/concerns/customer_organization.rb', line 115

def home_depot_usa?
  id == CustomerConstants::HOME_DEPOT_USA_ID
end

#homeowner?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/concerns/customer_organization.rb', line 92

def homeowner?
  profile_id == ProfileConstants::HOMEOWNER
end

#houzz?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'app/models/concerns/customer_organization.rb', line 167

def houzz?
  id == CustomerConstants::HOUZZ_ID
end

#include_po_prefix?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/concerns/customer_organization.rb', line 72

def include_po_prefix?
  CustomerConstants::SKIP_PREFIX_IN_PO_NUMBER_FOR_BILLING_ENTITY.exclude?(id)
end

#organization?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/concerns/customer_organization.rb', line 88

def organization?
  !homeowner?
end

#organization_family_idsArray<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.

Returns:

  • (Array<Integer>)


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

def organization_family_ids
  ([id, parent_id].compact + child_organizations.ids).uniq
end

#overstock_com?Boolean

Returns:

  • (Boolean)


187
188
189
190
191
# File 'app/models/concerns/customer_organization.rb', line 187

def overstock_com?
  name.to_s.casecmp('overstock.com').zero? ||
    (id == 303_919) ||
    catalog.name.to_s.casecmp('overstock.com').zero?
end

#parent_organization_nameObject



62
63
64
# File 'app/models/concerns/customer_organization.rb', line 62

def parent_organization_name
  parent_organization&.name
end

#part_of_lowes_ca?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'app/models/concerns/customer_organization.rb', line 147

def part_of_lowes_ca?
  [CustomerConstants::LOWES_CA_ID, CustomerConstants::RONA_CA_ID, CustomerConstants::RENO_CA_ID].include?(id)
end

#part_of_lowes_com?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'app/models/concerns/customer_organization.rb', line 151

def part_of_lowes_com?
  [CustomerConstants::LOWES_COM_ID].include?(id)
end

#person?Boolean

Returns:

  • (Boolean)


234
235
236
# File 'app/models/concerns/customer_organization.rb', line 234

def person?
  homeowner?
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.

Parameters:

Returns:

  • (Boolean)


30
31
32
# File 'app/models/concerns/customer_organization.rb', line 30

def same_organization_family?(other)
  other.present? && organization_family_ids.include?(other.id)
end

#self_and_children_idsObject



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

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 CustomerAliases.

Returns:

  • (Boolean)


99
100
101
# File 'app/models/concerns/customer_organization.rb', line 99

def trade_pro?
  profile&.trade_pro? || false
end

#update_buying_group(buying_group_id) ⇒ Object



217
218
219
# File 'app/models/concerns/customer_organization.rb', line 217

def update_buying_group(buying_group_id)
  CustomerBuyingGroupUpdater.call(self, buying_group_id)
end

#use_parent_billing_addressObject



209
210
211
# File 'app/models/concerns/customer_organization.rb', line 209

def use_parent_billing_address
  parent_organization&.billing_address_id && (parent_organization.billing_address_id == billing_address_id)
end

#use_parent_billing_address=(val) ⇒ Object



213
214
215
# File 'app/models/concerns/customer_organization.rb', line 213

def use_parent_billing_address=(val)
  self.record_parent_billing_address = ((val == '1') && val.present?)
end

#walmart_ca?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/models/concerns/customer_organization.rb', line 123

def walmart_ca?
  id == CustomerConstants::WALMART_CA_ID
end

#wasn4_or_wat0f?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/models/concerns/customer_organization.rb', line 139

def wasn4_or_wat0f?
  [CustomerConstants::AMAZON_VENDOR_CENTRAL_WASN4_CUSTOMER_ID, CustomerConstants::AMAZON_VENDOR_CENTRAL_WAT0F_CUSTOMER_ID].include?(id)
end

#wayfair?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'app/models/concerns/customer_organization.rb', line 155

def wayfair?
  [CustomerConstants::WAYFAIR_USA_ID, CustomerConstants::WAYFAIR_CA_ID].include?(id)
end

#wayfair_ca?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'app/models/concerns/customer_organization.rb', line 163

def wayfair_ca?
  id == CustomerConstants::WAYFAIR_CA_ID
end

#wayfair_usa?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'app/models/concerns/customer_organization.rb', line 159

def wayfair_usa?
  id == CustomerConstants::WAYFAIR_USA_ID
end

#zoro?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'app/models/concerns/customer_organization.rb', line 179

def zoro?
  id == CustomerConstants::ZORO_ID
end