diff --git a/app/controllers/audits_controller.rb b/app/controllers/audits_controller.rb index 5cb0f22d8b..8d68291cee 100644 --- a/app/controllers/audits_controller.rb +++ b/app/controllers/audits_controller.rb @@ -10,7 +10,7 @@ def index end def show - @items = View::Inventory.items_for_location(@audit.storage_location) + @items = View::Inventory.items_for_location(@audit.storage_location, include_omitted: true) end def edit @@ -93,7 +93,7 @@ def set_storage_locations end def set_items - @items = current_organization.items.alphabetized + @items = current_organization.items.where(active: true).alphabetized end def save_audit_status_and_redirect(params) diff --git a/app/views/audits/_form.html.erb b/app/views/audits/_form.html.erb index d9014cae5f..8cb798a588 100644 --- a/app/views/audits/_form.html.erb +++ b/app/views/audits/_form.html.erb @@ -14,7 +14,7 @@
<%= simple_form_for @audit, data: { controller: "form-input" }, html: {class: "storage-location-required"} do |f| %> - <%= render partial: "storage_locations/source", object: f, locals: { label: "Storage location", error: "What storage location are you auditing?" } %> + <%= render partial: "storage_locations/source", object: f, locals: { label: "Storage location", error: "What storage location are you auditing?", include_omitted_items: true } %>
Items in this audit
diff --git a/spec/requests/audits_requests_spec.rb b/spec/requests/audits_requests_spec.rb index 80d21de719..61ad5a38a8 100644 --- a/spec/requests/audits_requests_spec.rb +++ b/spec/requests/audits_requests_spec.rb @@ -50,6 +50,21 @@ get new_audit_path expect(response).to be_successful end + + it 'only includes active items in the line item select dropdown' do + create(:item, name: "TestActiveItem", organization: organization) + create(:item, name: "TestInactiveItem", organization: organization, active: false) + + get new_audit_path + expect(response).to have_http_status(:ok) + + html = Nokogiri::HTML(response.body) + options = html.css('select[name="audit[line_items_attributes][0][item_id]"] option') + option_values = options.map { |option| option.text.strip } + + expect(option_values).to include('TestActiveItem') + expect(option_values).not_to include('TestInactiveItem') + end end describe "GET #edit" do diff --git a/spec/system/audit_system_spec.rb b/spec/system/audit_system_spec.rb index 92df751ae5..69a0218ece 100644 --- a/spec/system/audit_system_spec.rb +++ b/spec/system/audit_system_spec.rb @@ -68,6 +68,36 @@ end end + it "allows auditing items that are not in a storage location", :js do + item = create(:item, name: "TestItemNotInStorageLocation", organization: organization) + audit_quantity = 1234 + visit new_audit_path + + await_select2("#audit_line_items_attributes_0_item_id") do + select storage_location.name, from: "Storage location" + end + select item.name, from: "audit_line_items_attributes_0_item_id" + fill_in "audit_line_items_attributes_0_quantity", with: audit_quantity + + accept_confirm do + click_button "Confirm Audit" + end + expect(page.find(".alert-info")).to have_content "Audit is confirmed" + expect(page).to have_content(item.name) + expect(page).to have_content(audit_quantity) + + accept_confirm do + click_link "Finalize Audit" + end + expect(page.find(".alert-info")).to have_content "Audit is Finalized" + + event = Event.last + expect(event.type).to eq "AuditEvent" + event_line_item = Event.last.data.items.first + expect(event_line_item.item_id).to eq item.id + expect(event_line_item.quantity).to eq audit_quantity + end + it "allows user to add items that do not yet have a barcode", :js do item_without_barcode = create(:item) new_barcode = "00000000"