Class: Item::CycleCountPrioritizer
Class Method Summary
collapse
Instance Method Summary
collapse
-
#initialize(options = {}) ⇒ CycleCountPrioritizer
constructor
aim to count every item once per 3 months minimum count item if drops below item.qty_warn_on_stock and last count more than 4 weeks ago items with unit_cogs > $200 counted every 2 weeks (46 as of 2/6/18) never count fixing strip, circuit check, warning label, face plate, brochure, catalog, poster, sample (too many to count) don't count anything with 0 in stock count items due to arrive soon more often.
-
#potential_store_items ⇒ Object
-
#process ⇒ Object
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
aim to count every item once per 3 months minimum
count item if drops below item.qty_warn_on_stock and last count more than 4 weeks ago
items with unit_cogs > $200 counted every 2 weeks (46 as of 2/6/18)
never count fixing strip, circuit check, warning label, face plate, brochure, catalog, poster, sample (too many to count)
don't count anything with 0 in stock
count items due to arrive soon more often
11
12
13
14
|
# File 'app/services/item/cycle_count_prioritizer.rb', line 11
def initialize(options = {})
@options = options
@logger = options[:logger] || Rails.logger
end
|
Class Method Details
.calculate_store_item_priority(si) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/services/item/cycle_count_prioritizer.rb', line 30
def self.calculate_store_item_priority(si)
priority = 0
return 0 if si.item.name.match(/fixing.*strip|circuit.*check|warning.*label|face.*plate|brochure|catalog|poster|sample/i)
return 0 if si.qty_on_hand.zero?
priority += 10
active_kit_parent_count = 0
si.item.kit_parents.each do |k|
if CatalogItem.where(state: %w(active active_hidden)).joins(:store_item).where(store_items: { item_id: k.id, location: 'AVAILABLE', store_id: si.store_id }).present?
active_kit_parent_count += 1
end
end
priority += 10 * active_kit_parent_count
priority += 30 if si.catalog_items.main_catalogs.public_catalog_items.any? || si.item.kit_parents.any? do |k|
k.catalog_items.main_catalogs.public_catalog_items.joins(:store_item).where(store_items: { store_id: si.store_id }).any?
end
last_counted = si.last_cycle_count.try(:date_processed)
if last_counted.nil?
priority += 500
else
months_since_last_counted = (Date.current.year * 12 + Date.current.month) - (last_counted.year * 12 + last_counted.month)
priority += months_since_last_counted * 10
end
if si.item.qty_warn_on_stock && (si.qty_on_hand <= si.item.qty_warn_on_stock) && (last_counted.nil? || (last_counted < 4.weeks.ago))
priority += 20
end
priority += 30 if si.on_order.any? do |details|
details[:promised_delivery_date] && (details[:promised_delivery_date] >= Date.current) && (details[:promised_delivery_date] <= Date.current + 7)
end && (last_counted.nil? || (last_counted < 2.weeks.ago))
priority += 20 if si.catalog_items.where(state: 'active').present?
priority += 20 if si.catalog_items.main_catalogs.where(state: %w(active active_hidden)).present?
priority += 100 if si.add_to_next_cycle_count?
priority
end
|
Instance Method Details
#potential_store_items ⇒ Object
81
82
83
84
85
86
|
# File 'app/services/item/cycle_count_prioritizer.rb', line 81
def potential_store_items
StoreItem.joins(item: :product_category).includes(:item)
.merge(ProductCategory.non_publications)
.where(location: 'AVAILABLE', is_discontinued: false,
items: { is_discontinued: false, is_kit: false })
end
|
#process ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/services/item/cycle_count_prioritizer.rb', line 16
def process
res = {}
StoreItem.transaction do
StoreItem.update_all(cycle_count_priority: 0)
potential_store_items.each do |si|
priority = self.class.calculate_store_item_priority(si)
si.update_attribute(:cycle_count_priority, priority) if priority > 0
res[si.id] = priority
end
end
res
end
|