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.
Instance Method Summary collapse
- #abbreviation_for_packing_list ⇒ Object
- #all_or_none_are_blank_in_address? ⇒ Boolean
- #amazon_com? ⇒ Boolean
- #amazon_seller_central? ⇒ Boolean
- #amazon_vendor_central? ⇒ Boolean
- #broadcast_buying_group_changed(buying_group_id_added: nil, buying_group_id_removed: nil) ⇒ Object
- #build_com? ⇒ Boolean
- #buying_group_company? ⇒ Boolean
- #buying_group_name ⇒ Object
- #buying_groups_options_for_select ⇒ Object
-
#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
- #certified_installer? ⇒ Boolean
- #company_name ⇒ Object
- #company_name=(val) ⇒ Object
- #costco_ca? ⇒ Boolean
- #customer_segment ⇒ Object
- #dealer? ⇒ Boolean
-
#dealer_or_trade_pro_for_locator? ⇒ Boolean
Legacy method kept for the dealer-locator call sites.
- #determine_company_id ⇒ Object
- #direct_buy? ⇒ Boolean
- #direct_buy_can? ⇒ Boolean
- #direct_buy_usa? ⇒ Boolean
- #e_commerce_misc? ⇒ Boolean
- #e_commerce_misc_or_direct_pro? ⇒ Boolean
- #effective_report_grouping ⇒ Object
- #home_depot_can? ⇒ Boolean
- #home_depot_usa? ⇒ Boolean
- #homeowner? ⇒ Boolean
- #houzz? ⇒ Boolean
- #include_po_prefix? ⇒ Boolean
- #organization? ⇒ Boolean
-
#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
- #parent_organization_name ⇒ Object
- #part_of_lowes_ca? ⇒ Boolean
- #part_of_lowes_com? ⇒ Boolean
- #person? ⇒ Boolean
-
#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 ⇒ Object
-
#trade_pro? ⇒ Boolean
Customer-level mirrors of
Profile#trade_pro?/Profile#dealer?. - #update_buying_group(buying_group_id) ⇒ Object
- #use_parent_billing_address ⇒ Object
- #use_parent_billing_address=(val) ⇒ Object
- #walmart_ca? ⇒ Boolean
- #wasn4_or_wat0f? ⇒ Boolean
- #wayfair? ⇒ Boolean
- #wayfair_ca? ⇒ Boolean
- #wayfair_usa? ⇒ Boolean
- #zoro? ⇒ Boolean
Instance Method Details
#abbreviation_for_packing_list ⇒ Object
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
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
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
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
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 (buying_group_id_added: nil, buying_group_id_removed: nil) CustomerBuyingGroupUpdater.broadcast(self, added: , removed: ) end |
#build_com? ⇒ 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
193 194 195 |
# File 'app/models/concerns/customer_organization.rb', line 193 def profile&.name&.include?('Buying Group') && ! end |
#buying_group_name ⇒ Object
58 59 60 |
# File 'app/models/concerns/customer_organization.rb', line 58 def &.name end |
#buying_groups_options_for_select ⇒ Object
54 55 56 |
# File 'app/models/concerns/customer_organization.rb', line 54 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.
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
171 172 173 |
# File 'app/models/concerns/customer_organization.rb', line 171 def canadian_tire? id == CustomerConstants::CANADIAN_TIRE_ID end |
#certified_installer? ⇒ Boolean
183 184 185 |
# File 'app/models/concerns/customer_organization.rb', line 183 def certified_installer? certifications.active.any? end |
#company_name ⇒ Object
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
143 144 145 |
# File 'app/models/concerns/customer_organization.rb', line 143 def costco_ca? id == CustomerConstants::COSTCO_CA_ID end |
#customer_segment ⇒ Object
226 227 228 229 230 231 232 |
# File 'app/models/concerns/customer_organization.rb', line 226 def customer_segment if organization? .nil? ? 'TP' : 'BG' else 'HO' end end |
#dealer? ⇒ 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.
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_id ⇒ Object
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
197 198 199 |
# File 'app/models/concerns/customer_organization.rb', line 197 def direct_buy? &.is_direct_buy? end |
#direct_buy_can? ⇒ Boolean
205 206 207 |
# File 'app/models/concerns/customer_organization.rb', line 205 def direct_buy_can? &.is_direct_buy_can? end |
#direct_buy_usa? ⇒ Boolean
201 202 203 |
# File 'app/models/concerns/customer_organization.rb', line 201 def direct_buy_usa? &.is_direct_buy_usa? end |
#e_commerce_misc? ⇒ 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
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_grouping ⇒ Object
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
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
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
92 93 94 |
# File 'app/models/concerns/customer_organization.rb', line 92 def homeowner? profile_id == ProfileConstants::HOMEOWNER end |
#houzz? ⇒ Boolean
167 168 169 |
# File 'app/models/concerns/customer_organization.rb', line 167 def houzz? id == CustomerConstants::HOUZZ_ID end |
#include_po_prefix? ⇒ 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
88 89 90 |
# File 'app/models/concerns/customer_organization.rb', line 88 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.
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
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_name ⇒ Object
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
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
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
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.
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_ids ⇒ Object
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.
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 () CustomerBuyingGroupUpdater.call(self, ) end |
#use_parent_billing_address ⇒ Object
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
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
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
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
163 164 165 |
# File 'app/models/concerns/customer_organization.rb', line 163 def wayfair_ca? id == CustomerConstants::WAYFAIR_CA_ID end |
#wayfair_usa? ⇒ Boolean
159 160 161 |
# File 'app/models/concerns/customer_organization.rb', line 159 def wayfair_usa? id == CustomerConstants::WAYFAIR_USA_ID end |
#zoro? ⇒ Boolean
179 180 181 |
# File 'app/models/concerns/customer_organization.rb', line 179 def zoro? id == CustomerConstants::ZORO_ID end |