Class: InventoryV2Worker::Service

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/workers/inventory_v2_worker.rb

Overview

Service class to handle the inventory generation logic. It processes the inventories for a specific restaurant and service type (dine_in or take_away). It can also clear existing inventories if Operation team click “remake” button

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_id, service_type, remade = false) ⇒ Service

Returns a new instance of Service.

Parameters:

  • restaurant_id (Integer)
  • service_type (String)

    either 'dine_in' or 'take_away'

  • remade (Boolean) (defaults to: false)

    if true, will clear existing inventories before processing



26
27
28
29
30
31
32
33
34
# File 'app/workers/inventory_v2_worker.rb', line 26

def initialize(restaurant_id, service_type, remade = false)
  @service_type = service_type.to_s
  @restaurant = Restaurant.find(restaurant_id)
  @remade = remade
  @model = select_model
  @date_to_generates = Set.new
  @inventories = []
  @inventories_of_updated_inventories = []
end

Instance Attribute Details

#date_to_generatesObject (readonly)

Returns the value of attribute date_to_generates.



21
22
23
# File 'app/workers/inventory_v2_worker.rb', line 21

def date_to_generates
  @date_to_generates
end

#modelObject (readonly)

Returns the value of attribute model.



21
22
23
# File 'app/workers/inventory_v2_worker.rb', line 21

def model
  @model
end

#remadeObject (readonly)

Returns the value of attribute remade.



21
22
23
# File 'app/workers/inventory_v2_worker.rb', line 21

def remade
  @remade
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



21
22
23
# File 'app/workers/inventory_v2_worker.rb', line 21

def restaurant
  @restaurant
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



21
22
23
# File 'app/workers/inventory_v2_worker.rb', line 21

def service_type
  @service_type
end

Instance Method Details

#callObject



36
37
38
39
40
41
42
43
# File 'app/workers/inventory_v2_worker.rb', line 36

def call
  # we don't sell take away products anymore
  return if @model == InventoryTakeAway

  clear_existing_inventories if remade
  process_inventories
  update_related_services
end