Class: SpreeCmCommissioner::InventoryItems::RecentlyChangedFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree_cm_commissioner/inventory_items/recently_changed_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(time_range: 7.days.ago, limit: 1000, vendor_id: nil, filter_type: 'all') ⇒ RecentlyChangedFinder

Returns a new instance of RecentlyChangedFinder.



4
5
6
7
8
9
# File 'app/finders/spree_cm_commissioner/inventory_items/recently_changed_finder.rb', line 4

def initialize(time_range: 7.days.ago, limit: 1000, vendor_id: nil, filter_type: 'all')
  @time_range = time_range
  @limit = limit
  @vendor_id = vendor_id
  @filter_type = filter_type
end

Instance Method Details

#executeObject

Finds recently changed items with Redis comparison Returns array of hashes sorted by biggest discrepancy first



13
14
15
16
17
18
19
# File 'app/finders/spree_cm_commissioner/inventory_items/recently_changed_finder.rb', line 13

def execute
  items = fetch_recent_items
  items_with_comparison = fetch_quantity_in_redis_batch(items)

  # Sort by biggest discrepancy first
  items_with_comparison.sort_by { |item| (item[:quantity_in_redis].to_i - item[:quantity_available]).abs }.reverse
end