Class: Item::MarketingCycleCountScheduler
- Inherits:
-
BaseService
- Object
- BaseService
- Item::MarketingCycleCountScheduler
- Defined in:
- app/services/item/marketing_cycle_count_scheduler.rb
Instance Method Summary collapse
-
#initialize(store_id, options = {}) ⇒ MarketingCycleCountScheduler
constructor
A new instance of MarketingCycleCountScheduler.
- #marketing_store_items ⇒ Object
- #process ⇒ Object
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, ={}) @store = Store.find(store_id) @due_date = [:due_date] || Date.current @options = @logger = [:logger] || Rails.logger end |
Instance Method Details
#marketing_store_items ⇒ Object
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 |
#process ⇒ Object
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 |