Skip to content

Commit d88243a

Browse files
seabeeberryseabeeberry
authored andcommitted
Fetching items by their IDs instead of their names
1 parent cf686c1 commit d88243a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

app/services/request_itemized_breakdown_service.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def fetch(organization:, request_ids:)
1212
items_requested = fetch_items_requested(organization: organization, request_ids: request_ids)
1313

1414
items_requested.each do |item|
15-
name = item[:name]
15+
id = item[:item_id]
1616

17-
on_hand = current_onhand[name]
18-
minimum = current_min_onhand[name]
17+
on_hand = current_onhand[id]
18+
minimum = current_min_onhand[id]
1919
below_onhand_minimum = on_hand && minimum && on_hand < minimum
2020

2121
item.merge!(
@@ -35,11 +35,11 @@ def csv(organization:, request_ids:)
3535
private
3636

3737
def current_onhand_quantities(inventory)
38-
inventory.all_items.group_by(&:name).to_h { |k, v| [k, v.sum { |r| r.quantity.to_i }] }
38+
inventory.all_items.group_by(&:item_id).to_h { |item_id, rows| [item_id, rows.sum { |r| r.quantity.to_i }] }
3939
end
4040

4141
def current_onhand_minimums(inventory)
42-
inventory.all_items.group_by(&:name).to_h { |k, v| [k, v.map(&:on_hand_minimum_quantity).compact.max] }
42+
inventory.all_items.group_by(&:item_id).to_h { |item_id, rows| [item_id, rows.map(&:on_hand_minimum_quantity).compact.max] }
4343
end
4444

4545
def fetch_items_requested(organization:, request_ids:)

0 commit comments

Comments
 (0)