Skip to content

Commit

Permalink
[rubyforgood#4594] allow zero inventory items to be selected for audi…
Browse files Browse the repository at this point in the history
…t and filter out inactive items
  • Loading branch information
danielabar committed Dec 8, 2024
1 parent d60dfae commit b9c7900
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/audits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/audits/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="box-body">
<%= 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 } %>
<fieldset style="margin-bottom: 2rem;">
<legend>Items in this audit</legend>
<div id="audit_line_items" class="line-item-fields" data-capture-barcode="true">
Expand Down
40 changes: 40 additions & 0 deletions spec/system/audit_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b9c7900

Please sign in to comment.