Skip to content

Commit 07e3e4c

Browse files
authored
Include inactive storage locations in csv (#5026)
* Include inactive storage locations in csv * Add spec for inactive storage location csv
1 parent f20a37c commit 07e3e4c

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

app/controllers/storage_locations_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def index
1212
@inventory = View::Inventory.new(current_organization.id)
1313
@selected_item_category = filter_params[:containing]
1414
@items = StorageLocation.items_inventoried(current_organization, @inventory)
15-
@include_inactive_storage_locations = params[:include_inactive_storage_locations].present?
15+
@include_inactive_storage_locations = params[:include_inactive_storage_locations]
1616
@storage_locations = current_organization.storage_locations.alphabetized
17+
1718
if filter_params[:containing].present?
1819
containing_ids = @inventory.storage_locations.keys.select do |sl|
1920
@inventory.quantity_for(item_id: filter_params[:containing], storage_location: sl).positive?

app/views/storage_locations/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<%= clear_filter_button %>
5151
<span class="float-right">
5252
<%= modal_button_to("#csvImportModal", {icon: "upload", text: "Import Storage Locations"}) if @storage_locations.empty? %>
53-
<%= download_button_to(storage_locations_path(format: :csv, filters: filter_params.merge(date_range: date_range_params)), {text: "Export Storage Locations", size: "md"}) if @storage_locations.any? %>
53+
<%= download_button_to(storage_locations_path(format: :csv, include_inactive_storage_locations: @include_inactive_storage_locations, filters: filter_params.merge(date_range: date_range_params)), {text: "Export Storage Locations", size: "md"}) if @storage_locations.any? %>
5454
<%= new_button_to new_storage_location_path, {text: "New Storage Location"} %>
5555
</span>
5656
</div>

spec/requests/storage_locations_requests_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,46 @@
161161
CSV
162162
expect(response.body).to eq(csv)
163163
end
164+
165+
context "when include inactive storage locations checkbox is checked" do
166+
let(:inactive_storage_location) {
167+
create(
168+
:storage_location,
169+
name: "Inactive Storage Location",
170+
address: "123 Donation Site Way",
171+
warehouse_type: StorageLocation::WAREHOUSE_TYPES.first,
172+
discarded_at: 5.months.ago
173+
)
174+
}
175+
176+
before do
177+
TestInventory.create_inventory(
178+
inactive_storage_location.organization, {
179+
inactive_storage_location.id => {
180+
item1.id => 1,
181+
item2.id => 1,
182+
item3.id => 1
183+
}
184+
}
185+
)
186+
end
187+
188+
it "generates csv with Storage Locations that are inactive" do
189+
get storage_locations_path(include_inactive_storage_locations: "1", format: response_format)
190+
191+
csv = <<~CSV
192+
Name,Address,Square Footage,Warehouse Type,Total Inventory,A,B,C,D
193+
Inactive Storage Location,123 Donation Site Way,100,Residential space used,3,1,1,1,0
194+
Storage Location with Duplicate Items,"1500 Remount Road, Front Royal, VA 22630",100,Residential space used,1,0,0,1,0
195+
Storage Location with Items,123 Donation Site Way,100,Residential space used,3,1,1,1,0
196+
Storage Location with Unique Items,Smithsonian Conservation Center new,100,Residential space used,5,0,0,0,5
197+
Test Storage Location,123 Donation Site Way,100,Residential space used,0,0,0,0,0
198+
Test Storage Location 1,123 Donation Site Way,100,Residential space used,0,0,0,0,0
199+
CSV
200+
201+
expect(response.body).to eq(csv)
202+
end
203+
end
164204
end
165205
end
166206

@@ -255,6 +295,7 @@
255295
end
256296
end
257297
end
298+
258299
describe "GET #show" do
259300
let(:item) { create(:item, name: "Test Item") }
260301
let(:item2) { create(:item, name: "Test Item2") }

0 commit comments

Comments
 (0)