Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/distribution_itemized_breakdown_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def distributions
end

def current_onhand_quantities(inventory)
inventory.all_items.group_by(&:name).to_h { |k, v| [k, v.sum(&:quantity)] }
inventory.all_items.each_with_object(Hash.new(0)) { |i, h| h[i.name] += i.quantity }
end

def current_onhand_minimums(inventory)
Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/itemized_distributions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<td><%= item[:name] %></td>
<td class="text-right"><%= item[:distributed] %></td>
<td class="text-right <%= 'table-danger' if item[:below_onhand_minimum] %>">
<%= item[:current_onhand] || "Unknown" %>
<%= item[:current_onhand] %>
</td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/itemized_donations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<tr>
<td><%= item[:name] %></td>
<td class="text-right"><%= item[:donated] %></td>
<td class="text-right"><%= item[:current_onhand] || "Unknown" %></td>
<td class="text-right"><%= item[:current_onhand] %></td>
</tr>
<% end %>
</tbody>
Expand Down
11 changes: 11 additions & 0 deletions spec/services/distribution_itemized_breakdown_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
it "should include the break down of items distributed with onhand data" do
expect(subject).to eq(expected_output)
end

context "#fetch with inactive item" do
let(:inactive_item) { create(:item, :inactive, organization: organization, name: "Inactive Item") }
let(:distribution) { create(:distribution, :with_items, item: inactive_item, organization: organization) }
let(:service) { described_class.new(organization: organization, distribution_ids: [distribution.id]) }

it "returns current_onhand as 0 for inactive items" do
result = service.fetch
expect(result.find { |i| i[:name] == inactive_item.name }[:current_onhand]).to eq(0)
end
end
end

describe "#fetch_csv" do
Expand Down