Module: Models::CustomerPricing
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer
- Defined in:
- app/concerns/models/customer_pricing.rb
Overview
Tier-2 pricing, discount propagation, shipping option names used for order defaults, pricing program.
Instance Attribute Summary collapse
-
#propagate_discount ⇒ Object
:reek:Attribute -- callback flag, not public API.
Instance Method Summary collapse
-
#apply_discount_level_to_open_children ⇒ Object
Direct entry point used by Merger::CustomerMerger after merging two customers so the master customer's open itemizables are repriced without going through the after_commit broadcast (which only fires on tier2 program pricing change).
-
#broadcast_discount_level_changed ⇒ Object
Published after_commit on update when set_propagate_discount captured a tier2 pricing change.
-
#pricing_program_description ⇒ String
Human-readable description of the customer's tier-2 pricing program.
-
#pricing_program_discount ⇒ BigDecimal, Float
Percentage discount on goods granted by the customer's tier-2 pricing program.
-
#pricing_program_discount_factor ⇒ BigDecimal
Multiplicative discount factor (percentage / 100, rounded to 2 decimals).
-
#set_default_for_opportunity(new_opp) ⇒ Opportunity
-- Rails before_add callback name.
-
#set_default_for_order(new_order) ⇒ Object
Rails before_add callback: applies customer defaults (pricing, shipping) to an order being added to this customer.
Instance Attribute Details
#propagate_discount ⇒ Object
:reek:Attribute -- callback flag, not public API
10 11 12 |
# File 'app/concerns/models/customer_pricing.rb', line 10 def propagate_discount @propagate_discount end |
Instance Method Details
#apply_discount_level_to_open_children ⇒ Object
Direct entry point used by Merger::CustomerMerger after merging two customers
so the master customer's open itemizables are repriced without going through
the after_commit broadcast (which only fires on tier2 program pricing change).
18 19 20 |
# File 'app/concerns/models/customer_pricing.rb', line 18 def apply_discount_level_to_open_children Pricing::DiscountLevelChangedHandler.call_for(self) end |
#broadcast_discount_level_changed ⇒ Object
Published after_commit on update when set_propagate_discount captured a
tier2 pricing change. Pricing::DiscountLevelChangedHandler subscribes.
26 27 28 29 30 31 |
# File 'app/concerns/models/customer_pricing.rb', line 26 def broadcast_discount_level_changed Rails.configuration.event_store.publish( Events::DiscountLevelChanged.new(data: { customer_id: id }), stream_name: "Customer-#{id}" ) end |
#pricing_program_description ⇒ String
Human-readable description of the customer's tier-2 pricing program.
Falls back to the parent catalog name for MSRP programs that have a
catalog-level discount, and to 'Unknown' when no program is assigned.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/concerns/models/customer_pricing.rb', line 38 def pricing_program_description if tier2_program_pricing if tier2_program_pricing.msrp? && catalog.parent_catalog_discount "Catalog #{catalog.name}" else tier2_program_pricing.title end else 'Unknown' end end |
#pricing_program_discount ⇒ BigDecimal, Float
Percentage discount on goods granted by the customer's tier-2 pricing
program.
54 55 56 |
# File 'app/concerns/models/customer_pricing.rb', line 54 def pricing_program_discount tier2_program_pricing&.amount_goods || 0.0 end |
#pricing_program_discount_factor ⇒ BigDecimal
Multiplicative discount factor (percentage / 100, rounded to 2 decimals).
61 62 63 |
# File 'app/concerns/models/customer_pricing.rb', line 61 def pricing_program_discount_factor (pricing_program_discount.to_f / 100).round(2) end |
#set_default_for_opportunity(new_opp) ⇒ Opportunity
-- Rails before_add callback name
Assigns a default name and propagates the buying group when an
opportunity is added to this customer.
72 73 74 75 76 |
# File 'app/concerns/models/customer_pricing.rb', line 72 def set_default_for_opportunity(new_opp) new_opp.name ||= next_opportunity_name(new_opp.name) new_opp. = new_opp end |
#set_default_for_order(new_order) ⇒ Object
Rails before_add callback: applies customer defaults (pricing, shipping)
to an order being added to this customer.
84 85 86 |
# File 'app/concerns/models/customer_pricing.rb', line 84 def set_default_for_order(new_order) OrderCustomerDefaultsApplier.call(order: new_order, customer: self) end |