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: {}) ⇒ Result
Status and any material alerts.
- #qualify?(container) ⇒ Boolean
Instance Method Details
#get_thermalsheets(container) ⇒ Object (protected)
57 58 59 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 57 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)
49 50 51 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 49 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)
53 54 55 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 53 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)
61 62 63 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 61 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: {}) ⇒ Result
Returns status and any material alerts.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/item/materials/checks/tz_cable_tape_roll.rb', line 23 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 |