Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4594] allow zero inventory items to be selected for audit #4833

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions spec/requests/audits_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/system/audit_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading