Class: Item::Materials::Checks::TzCableTapeRoll

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/item/materials/checks/tz_cable_tape_roll.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

STRIPS_PER_TAPE_ROLL =
26.0

Instance Method Summary collapse

Instance Method Details

#get_thermalsheets(container) ⇒ Object (protected)



49
50
51
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 49

def get_thermalsheets(container)
  container.line_items.insulations.by_product_line_path(LtreePaths::PL_FLOOR_HEATING_UNDERLAYMENT_THERMALSHEET).to_a
end

#get_tz_cable_heating_elements(container) ⇒ Object (protected)



41
42
43
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 41

def get_tz_cable_heating_elements(container)
  container.line_items.heating_elements.by_product_line_path(LtreePaths::PL_FLOOR_HEATING_TEMPZONE_CABLE).to_a
end

#get_tz_cable_strips(container) ⇒ Object (protected)



45
46
47
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 45

def get_tz_cable_strips(container)
  container.line_items.joins(:item).merge(Item.where(sku: ItemConstants::TZ_CABLE_STRIP_SKUS))
end

#get_tz_cable_tape_rolls(container) ⇒ Object (protected)



53
54
55
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 53

def get_tz_cable_tape_rolls(container)
  container.line_items.accessories.sku_and_aliases_search(ItemConstants::TZ_CABLE_TAPE_SKU).to_a
end

#process(container:, options: {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 15

def process(container:, options:{})
  # first test if we have any floor heating element products
  tz_cable_heating_elements = get_tz_cable_heating_elements(container)
  tz_strips = get_tz_cable_strips(container)
  thermalsheets = get_thermalsheets(container)
  return Result.new(status: :skipped) unless qualify?(container) && tz_cable_heating_elements.present? && tz_strips.present? && thermalsheets.present?

  material_alerts = []
  # when these appear together (nd not in a room config because it will get the same recommendation via the AccessoriesFinder) it means we should recommend double sided tape rolls
  num_tz_strips = tz_strips.sum{|li| li.quantity}
  num_current_tz_tape_rolls = get_tz_cable_tape_rolls(container).sum{|li| li.quantity}
  num_tz_tape_rolls_rec = (num_tz_strips / STRIPS_PER_TAPE_ROLL).ceil
  unless num_tz_tape_rolls_rec == num_current_tz_tape_rolls
    ma_options = {}.merge(options)
    ma_options[:room] = container
    ma_options[:recommended_qty] = num_tz_tape_rolls_rec
    ma_options[:actual_qty] = num_current_tz_tape_rolls
    ma_options[:items] = [Item::Materials::Check.find_item_by_sku(ItemConstants::TZ_CABLE_TAPE_SKU)]
    material_alerts << Item::Materials::Alert.new(ma_options)
  end

  return Result.new(status: :ok, alerts: material_alerts)
end

#qualify?(container) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 10

def qualify?(container)
  # we only apply this test when a container is a quote or order with no rooms, ie a single system
  (container.respond_to?(:room_configurations) && container.room_configurations.count == 0)
end