Class: Item::MarketingCycleCountScheduler

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/item/marketing_cycle_count_scheduler.rb

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

#initialize(store_id, options = {}) ⇒ MarketingCycleCountScheduler

Returns a new instance of MarketingCycleCountScheduler.



3
4
5
6
7
8
# File 'app/services/item/marketing_cycle_count_scheduler.rb', line 3

def initialize(store_id, options={})
  @store = Store.find(store_id)
  @due_date = options[:due_date] || Date.current
  @options = options
  @logger = options[:logger] || Rails.logger
end

Instance Method Details

#marketing_store_itemsObject



22
23
24
# File 'app/services/item/marketing_cycle_count_scheduler.rb', line 22

def marketing_store_items
  StoreItem.active.joins(:item).merge(Item.marketing).where(store_id: @store.id, location: 'AVAILABLE')
end

#processObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/item/marketing_cycle_count_scheduler.rb', line 10

def process
  return "Draft Cycle Count already found" if CycleCount.where(store_id: @store.id, state: 'draft', marketing_only: true).any?
  cycle_count = CycleCount.new(store_id: @store.id, due_date: @due_date, marketing_only: true)

  marketing_store_items.each do |si|
    cycle_count.cycle_count_items.build(item_id: si.item_id, location: si.location)
  end

  cycle_count.save
  cycle_count
end