Skip to content

Commit

Permalink
Location name could be duplicated, so use id to identify the location…
Browse files Browse the repository at this point in the history
… instead.
  • Loading branch information
ChaelCodes committed Jul 30, 2023
1 parent d160974 commit df90cac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions app/queries/items_by_storage_collection_and_quantity_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ def call
item_on_hand_recommended_quantity: row.on_hand_recommended_quantity,
item_value: row.value_in_cents,
item_barcode_count: row.barcode_count,
locations: {},
locations: [],
quantity: 0
}
end
@items_by_storage_collection_and_quantity[row.id][:locations][row.storage_name] = row.quantity

if row.storage_id
@items_by_storage_collection_and_quantity[row.id][:locations] << {
id: row.storage_id,
name: row.storage_name,
quantity: row.quantity
}
end
@items_by_storage_collection_and_quantity[row.id][:quantity] += row.quantity || 0
end

Expand Down
7 changes: 4 additions & 3 deletions app/views/items/_item_row_inventory.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<tr class="expandable-body">
<td colspan="5">
<p>
<% row_item[:locations].each do |location_name, quantity| %>
<%= "#{location_name} - #{quantity} units" %><br>
<% row_item[:locations].each do |location| %>
<%= link_to(location[:name], storage_location_url(location[:id])) %>
<%= " - #{location[:quantity]} units" %><br>
<% end %>
</p>
</td>
</tr>
</tr>
4 changes: 3 additions & 1 deletion app/views/items/_item_row_quantity_and_storages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<tr>
<td><%= link_to(row_item[:item_name], item_url(row_item[:item_id])) %></td>
<% @storages.each do |storage| %>
<td class="numeric"><%= row_item[:locations][storage.name] || "0" %></td>
<td class="numeric">
<%= row_item[:locations].find { |location| location[:id] == storage.id }&.dig(:quantity) || "0" %>
</td>
<% end %>
<td class="numeric"><%= row_item[:item_on_hand_minimum_quantity] %></td>
<td class="numeric"><%= row_item[:item_on_hand_recommended_quantity] %></td>
Expand Down
3 changes: 2 additions & 1 deletion spec/system/item_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
expandable_row = find("td", text: item_tampons.name).find(:xpath, "..")
expandable_row.click
expanded_row = find(".expandable-body", visible: true).text
expect(expanded_row).to have_content storage_name
expect(find(".expandable-body", visible: true)).to have_link storage_name
expect(expanded_row).to have_link storage_name
expect(expanded_row).to have_content num_tampons_in_donation
expect(expanded_row).to have_content num_tampons_second_donation
end
Expand Down

0 comments on commit df90cac

Please sign in to comment.