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

Add warning for intervening audits on distribution edit #4026

Merged
merged 3 commits into from
Jan 14, 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
3 changes: 3 additions & 0 deletions app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def edit
@distribution.line_items.build if @distribution.line_items.size.zero?
@items = current_organization.items.alphabetized
@storage_locations = current_organization.storage_locations.active_locations.has_inventory_items.alphabetized
@audit_warning = current_organization.audits
.where(storage_location_id: @distribution.storage_location_id)
.where("updated_at > ?", @distribution.created_at).any?
else
cielf marked this conversation as resolved.
Show resolved Hide resolved
redirect_to distributions_path, error: 'To edit a distribution,
you must be an organization admin or the current date must be later than today.'
Expand Down
13 changes: 11 additions & 2 deletions app/views/distributions/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@
<section class="content">

<% unless @distribution.future? %>
<div class="alert alert-warning" , role="alert">
<div class="alert alert-warning" role="alert">
The current date is past the date this distribution was scheduled for.
Please be very careful when editing this record;
the contents should match what was given to the recipient.
</div>
<% end %>
<% if @audit_warning %>
<div class="alert alert-warning" role="alert">
You’ve had an audit since this distribution was started.
In the rare case that you are correcting a typo,
rather than recording that the physical amounts being distributed have changed,
you’ll need to make an adjustment to the inventory as well.
</div>
<% end %>

<div class="container-fluid">
<div class="row">
Expand All @@ -48,7 +56,8 @@
<div class="box-body">
<%= render 'form', distribution: @distribution, date_place_holder: @distribution.issued_at %>
</div>
</div><!-- /.box -->
</div><!-- /.box -->
</div>
</div>
</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions spec/requests/distributions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@
end
end
end

describe "GET #edit" do
let(:location) { create(:storage_location) }
let(:partner) { create(:partner) }

let(:distribution) { create(:distribution, partner: partner) }

it "should show the distribution" do
get edit_distribution_path(default_params.merge(id: distribution.id))
expect(response).to be_successful
expect(response.body).not_to include("You’ve had an audit since this distribution was started.")
end

it "should show a warning if there is an inteverning audit" do
distribution.update!(created_at: 1.week.ago)
create(:audit, storage_location: distribution.storage_location)
get edit_distribution_path(default_params.merge(id: distribution.id))
expect(response.body).to include("You’ve had an audit since this distribution was started.")
end

it "should not show a warning if the audit is for another location" do
distribution.update!(created_at: 1.week.ago)
create(:audit, storage_location: create(:storage_location))
get edit_distribution_path(default_params.merge(id: distribution.id))
expect(response.body).not_to include("You’ve had an audit since this distribution was started.")
end
end
end

context "While not signed in" do
Expand Down
Loading