diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 4c782d567f..95dd39c482 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -12,8 +12,9 @@ def index @inventory = View::Inventory.new(current_organization.id) @selected_item_category = filter_params[:containing] @items = StorageLocation.items_inventoried(current_organization, @inventory) - @include_inactive_storage_locations = params[:include_inactive_storage_locations].present? + @include_inactive_storage_locations = params[:include_inactive_storage_locations] @storage_locations = current_organization.storage_locations.alphabetized + if filter_params[:containing].present? containing_ids = @inventory.storage_locations.keys.select do |sl| @inventory.quantity_for(item_id: filter_params[:containing], storage_location: sl).positive? diff --git a/app/views/storage_locations/index.html.erb b/app/views/storage_locations/index.html.erb index 4bf6b6dcc6..117989a426 100644 --- a/app/views/storage_locations/index.html.erb +++ b/app/views/storage_locations/index.html.erb @@ -50,7 +50,7 @@ <%= clear_filter_button %> <%= modal_button_to("#csvImportModal", {icon: "upload", text: "Import Storage Locations"}) if @storage_locations.empty? %> - <%= 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? %> + <%= 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? %> <%= new_button_to new_storage_location_path, {text: "New Storage Location"} %> diff --git a/spec/requests/storage_locations_requests_spec.rb b/spec/requests/storage_locations_requests_spec.rb index 4540d4479e..fb9b4ab622 100644 --- a/spec/requests/storage_locations_requests_spec.rb +++ b/spec/requests/storage_locations_requests_spec.rb @@ -161,6 +161,46 @@ CSV expect(response.body).to eq(csv) end + + context "when include inactive storage locations checkbox is checked" do + let(:inactive_storage_location) { + create( + :storage_location, + name: "Inactive Storage Location", + address: "123 Donation Site Way", + warehouse_type: StorageLocation::WAREHOUSE_TYPES.first, + discarded_at: 5.months.ago + ) + } + + before do + TestInventory.create_inventory( + inactive_storage_location.organization, { + inactive_storage_location.id => { + item1.id => 1, + item2.id => 1, + item3.id => 1 + } + } + ) + end + + it "generates csv with Storage Locations that are inactive" do + get storage_locations_path(include_inactive_storage_locations: "1", format: response_format) + + csv = <<~CSV + Name,Address,Square Footage,Warehouse Type,Total Inventory,A,B,C,D + Inactive Storage Location,123 Donation Site Way,100,Residential space used,3,1,1,1,0 + Storage Location with Duplicate Items,"1500 Remount Road, Front Royal, VA 22630",100,Residential space used,1,0,0,1,0 + Storage Location with Items,123 Donation Site Way,100,Residential space used,3,1,1,1,0 + Storage Location with Unique Items,Smithsonian Conservation Center new,100,Residential space used,5,0,0,0,5 + Test Storage Location,123 Donation Site Way,100,Residential space used,0,0,0,0,0 + Test Storage Location 1,123 Donation Site Way,100,Residential space used,0,0,0,0,0 + CSV + + expect(response.body).to eq(csv) + end + end end end @@ -255,6 +295,7 @@ end end end + describe "GET #show" do let(:item) { create(:item, name: "Test Item") } let(:item2) { create(:item, name: "Test Item2") }