Class: Item::Materials::Checks::CerazorbLimit

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

Overview

OBSOLETE DO NOT USE ####
Cerazorb is no longer sold, ThermalSheet does not have these constraints

Defined Under Namespace

Classes: Result

Constant Summary collapse

THRESHOLD_MAX =

Threshold max.

100

Instance Method Summary collapse

Instance Method Details

#cz_2x2_lines(container) ⇒ Object (protected)



36
37
38
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 36

def cz_2x2_lines(container)
  container.line_items.joins(:item).where(items: { sku: %w[CZRG-SH5MM-24X24 CZRG-SH5MM-24X24-P12] })
end

#cz_2x2_quantities(container) ⇒ Object (protected)



40
41
42
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 40

def cz_2x2_quantities(container)
  cz_2x2_lines(container).sum { |li| li.item.is_kit? ? li.quantity * li.item.kit_target_item_relations.sum(:quantity) : li.quantity }
end

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

rubocop:disable Lint/UnusedMethodArgument
options: is part of the shared Item::Materials::Checks polymorphic API
invoked by Item::Materials::Check#perform_checks_raw. Even though this
particular check ignores the value, the kwarg name has to stay as
options: so the bulk dispatch site keeps working.
:reek:UnusedParameters



23
24
25
26
27
28
29
30
31
32
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 23

def process(container:, options: {})
  # rubocop:enable Lint/UnusedMethodArgument
  return Result.new(status: :skipped) unless qualify?(container)

  material_alerts = []
  if (qty = cz_2x2_quantities(container)) > THRESHOLD_MAX
    material_alerts << Item::Materials::Alert.new(name: "You're exceeding the maximum recommended number of 2x2 Cerazorb sheets (#{qty}, maximum recommended: #{THRESHOLD_MAX}), please switch to 4x4 sheets", container: container)
  end
  Result.new(status: :ok, alerts: material_alerts)
end

#qualify?(container) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 13

def qualify?(container)
  cz_2x2_lines(container).exists?
end