Class: Item::Materials::Checks::TzCableTapeRoll
- Inherits:
-
BaseService
- Object
- BaseService
- Item::Materials::Checks::TzCableTapeRoll
- Defined in:
- app/services/item/materials/checks/tz_cable_tape_roll.rb
Overview
Service object: tz cable tape roll.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- STRIPS_PER_TAPE_ROLL =
Strips per tape roll.
26.0
Instance Method Summary collapse
- #get_thermalsheets(container) ⇒ Object protected
- #get_tz_cable_heating_elements(container) ⇒ Object protected
- #get_tz_cable_strips(container) ⇒ Object protected
- #get_tz_cable_tape_rolls(container) ⇒ Object protected
- #process(container:, options: {}) ⇒ Object
- #qualify?(container) ⇒ Boolean
Instance Method Details
#get_thermalsheets(container) ⇒ Object (protected)
52 53 54 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 52 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)
44 45 46 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 44 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)
48 49 50 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 48 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)
56 57 58 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 56 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 18 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(&:quantity) num_current_tz_tape_rolls = get_tz_cable_tape_rolls(container).sum(&: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 = {}.merge() [:room] = container [:recommended_qty] = num_tz_tape_rolls_rec [:actual_qty] = num_current_tz_tape_rolls [:items] = [Item::Materials::Check.find_item_by_sku(ItemConstants::TZ_CABLE_TAPE_SKU)] material_alerts << Item::Materials::Alert.new() end Result.new(status: :ok, alerts: material_alerts) end |
#qualify?(container) ⇒ Boolean
13 14 15 16 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 13 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.none? end |