Class: Item::Materials::Checks::TowelWarmer
- Inherits:
-
BaseService
- Object
- BaseService
- Item::Materials::Checks::TowelWarmer
- Defined in:
- app/services/item/materials/checks/towel_warmer.rb
Overview
Service object: towel warmer.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#process(container:, options: {}) ⇒ Result
Status and any material alerts.
- #qualify?(container) ⇒ Boolean
Instance Method Details
#process(container:, options: {}) ⇒ Result
Returns status and any material alerts.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/item/materials/checks/towel_warmer.rb', line 18 def process(container:, options: {}) return Result.new(status: :skipped) unless qualify?(container) material_alerts = [] num_towel_warmers_dual = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_dual_connect? }.sum(&:quantity) num_towel_warmers_plug_in = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_plug_in? }.sum(&:quantity) num_towel_warmers_hardwired = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_hardwired? }.sum(&:quantity) num_towel_warmer_controls_plug_in = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_plug_in_control? }.sum(&:quantity) num_towel_warmer_controls_hardwired = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_hardwired_control? }.sum(&:quantity) # test if we don't match the number of plugin controls to plugin towel warmers as well as that we don't match the number of plugin and dual connect towel warmers if (num_towel_warmer_controls_plug_in != num_towel_warmers_plug_in) && (num_towel_warmer_controls_plug_in != num_towel_warmers_plug_in + num_towel_warmers_dual) && container.catalog.catalog_items.by_skus(Item.towel_warmer_controls_plug_in.pluck(:sku)).public_catalog_items.any? diff_qty = num_towel_warmer_controls_plug_in - (num_towel_warmers_plug_in + num_towel_warmers_dual) = {}.merge() [:room] = container [:recommended_qty] = diff_qty.positive? ? (num_towel_warmers_plug_in + num_towel_warmers_dual) : num_towel_warmers_plug_in # recommended should reflect the number of plugin and dual connect towel warmers, only recommend the smallest change necessary [:actual_qty] = num_towel_warmer_controls_plug_in [:items] = if (ctrl_lis = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_plug_in_control? }).any? ctrl_lis.map(&:item) else Item.towel_warmer_controls_plug_in.to_a end [:unmaskable] = true [:name] = "One plug in control per plug in towel warmer is recommended." material_alerts << Item::Materials::Alert.new() end # test if we don't match the number of hardwired controls to hardwired towel warmers as well as that we don't match the number of hardwired and dual connect towel warmers if (num_towel_warmer_controls_hardwired != num_towel_warmers_hardwired) && (num_towel_warmer_controls_hardwired != num_towel_warmers_hardwired + num_towel_warmers_dual) && container.catalog.catalog_items.by_skus(Item.towel_warmer_controls_hardwired.pluck(:sku)).public_catalog_items.any? diff_qty = num_towel_warmer_controls_hardwired - (num_towel_warmers_hardwired + num_towel_warmers_dual) = {}.merge() [:room] = container [:recommended_qty] = diff_qty.positive? ? (num_towel_warmers_hardwired + num_towel_warmers_dual) : num_towel_warmers_hardwired # recommended should reflect the number of hardwired and dual connect towel warmers, only recommend the smallest change necessary [:actual_qty] = num_towel_warmer_controls_hardwired [:items] = if (ctrl_lis = container.line_items.parents_only.select { |l| l.item.is_towel_warmer_hardwired_control? }).any? ctrl_lis.map(&:item) else Item.towel_warmer_controls_hardwired.order_towel_warmer_controls_hardwired.to_a end [:unmaskable] = true [:name] = "One hardwired control per hardwired towel warmer is recommended." material_alerts << Item::Materials::Alert.new() end Result.new(status: :ok, alerts: material_alerts) end |
#qualify?(container) ⇒ Boolean
9 10 11 |
# File 'app/services/item/materials/checks/towel_warmer.rb', line 9 def qualify?(container) container.line_items.any? { |li| li.item.is_towel_warmer? } end |