Module: CustomerPricing

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

Overview

Tier-2 pricing, discount propagation, shipping option names used for order defaults, pricing program.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#propagate_discountObject

:reek:Attribute -- callback flag, not public API



10
11
12
# File 'app/models/concerns/customer_pricing.rb', line 10

def propagate_discount
  @propagate_discount
end

Instance Method Details

#apply_discount_level_to_open_childrenObject

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



16
17
18
# File 'app/models/concerns/customer_pricing.rb', line 16

def apply_discount_level_to_open_children
  Pricing::DiscountLevelChangedHandler.call_for(self)
end

#broadcast_discount_level_changedObject

Published after_commit on update when set_propagate_discount captured a
tier2 pricing change. Pricing::DiscountLevelChangedHandler subscribes.



22
23
24
25
26
27
# File 'app/models/concerns/customer_pricing.rb', line 22

def broadcast_discount_level_changed
  Rails.configuration.event_store.publish(
    Events::DiscountLevelChanged.new(data: { customer_id: id }),
    stream_name: "Customer-#{id}"
  )
end

#pricing_program_descriptionObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/customer_pricing.rb', line 29

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_discountObject



41
42
43
# File 'app/models/concerns/customer_pricing.rb', line 41

def pricing_program_discount
  tier2_program_pricing&.amount_goods || 0.0
end

#pricing_program_discount_factorObject



45
46
47
# File 'app/models/concerns/customer_pricing.rb', line 45

def pricing_program_discount_factor
  (pricing_program_discount.to_f / 100).round(2)
end

#set_default_for_opportunity(new_opp) ⇒ Object

rubocop:disable Naming/AccessorMethodName -- Rails before_add callback name



50
51
52
53
54
# File 'app/models/concerns/customer_pricing.rb', line 50

def set_default_for_opportunity(new_opp)
  new_opp.name ||= next_opportunity_name(new_opp.name)
  new_opp.buying_group_id = buying_group_id
  new_opp
end

#set_default_for_order(new_order) ⇒ Object



56
57
58
# File 'app/models/concerns/customer_pricing.rb', line 56

def set_default_for_order(new_order)
  OrderCustomerDefaultsApplier.call(order: new_order, customer: self)
end