From b9c790022161694eef4f662ed8528178df1e63ba Mon Sep 17 00:00:00 2001 From: Daniela Baron Date: Mon, 2 Dec 2024 06:06:30 -0500 Subject: [PATCH] [#4594] allow zero inventory items to be selected for audit and filter out inactive items --- app/controllers/audits_controller.rb | 4 +-- app/views/audits/_form.html.erb | 2 +- spec/system/audit_system_spec.rb | 40 ++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) 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/system/audit_system_spec.rb b/spec/system/audit_system_spec.rb index 92df751ae5..83e049d29a 100644 --- a/spec/system/audit_system_spec.rb +++ b/spec/system/audit_system_spec.rb @@ -68,6 +68,46 @@ 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 "does not display inactive items for selection" do + item = create(:item, name: "TestInactiveItem", organization: organization, active: false) + create(:storage_location, :with_items, item: item, item_quantity: 10, organization: organization) + visit new_audit_path + + select_element = find('#audit_line_items_attributes_0_item_id', visible: :all) + option_texts = select_element.all('option', visible: :all).map(&:text) + expect(option_texts).not_to include(item.name) + end + it "allows user to add items that do not yet have a barcode", :js do item_without_barcode = create(:item) new_barcode = "00000000"