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 1 commit
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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be moved to a request test? Since we're not testing interaction, it should be fine to do that and it's a lot more lightweight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to audit request test.

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
Loading