Class: Item::Materials::Checks::RoughinAndInstallKit

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

Overview

PS: I would rather not have this, it appears online as well and confuses customers, specially if they did the quote themselves or look at the quote
we provided

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

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



13
14
15
16
17
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
# File 'app/services/item/materials/checks/roughin_and_install_kit.rb', line 13

def process(container:, options:{})
  return Result.new(status: :skipped) unless qualify?(container)
  material_alerts = []
  
  invalid_install_kits = container.line_items.select{|l| l.item.exclusive_item_group and IqAccessoryFilter.for_item_or_exclusive_item_group(l.item.exclusive_item_group).for_customer(container.customer).first}.map{|li| li.item}
  invalid_rough_in_kits = container.line_items.select{|l| l.item.is_roughin_kit? and IqAccessoryFilter.for_item_or_exclusive_item_group(l.item).for_customer(container.customer).first}.map{|li| li.item}
  if invalid_install_kits.any?
    ma_options = {}.merge(options)
    ma_options[:room] = container
    ma_options[:group_type] = 'installation_kits'
    ma_options[:group_name] = "Installation Kits"
    ma_options[:recommended_qty] = 0
    ma_options[:actual_qty] = 1
    ma_options[:items] = invalid_install_kits
    ma_options[:unmaskable] = true
    ma_options[:name] = "We do not recommend adding Installation Kits to quote/orders for this customer."
    material_alerts << Item::Materials::Alert.new(ma_options)
  end
  if invalid_rough_in_kits.any?
    ma_options = {}.merge(options)
    ma_options[:room] = container
    ma_options[:recommended_qty] = 0
    ma_options[:actual_qty] = 1
    ma_options[:items] = invalid_rough_in_kits
    ma_options[:unmaskable] = true
    ma_options[:name] = "We do not recommend adding Rough-in Kits to quote/orders for this customer."
    material_alerts << Item::Materials::Alert.new(ma_options)
  end
  
  Result.new(status: :ok, alerts: material_alerts)
end

#qualify?(container) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/services/item/materials/checks/roughin_and_install_kit.rb', line 9

def qualify?(container)
  container.line_items.any?{|li| (li.item.exclusive_item_group and li.item.exclusive_item_group.key == "installation_kits") or li.item.is_roughin_kit?}
end