diff --git a/app/controllers/distributions_controller.rb b/app/controllers/distributions_controller.rb
index 7e7bd7649b..d0b1f56aeb 100644
--- a/app/controllers/distributions_controller.rb
+++ b/app/controllers/distributions_controller.rb
@@ -109,9 +109,9 @@ def create
else
@distribution = result.distribution
if request_id
- # Using .find here instead of .find_by so we can raise a error if request_id
- # does not match any known Request
- @distribution.request = Request.find(request_id)
+ @request = Request.find(request_id)
+ @distribution.request = @request
+ @distribution.partner = @request.partner
end
if @distribution.line_items.size.zero?
@distribution.line_items.build
@@ -148,7 +148,8 @@ def create
def new
@distribution = Distribution.new
if params[:request_id]
- @distribution.copy_from_request(params[:request_id])
+ @request = Request.find(request_id)
+ @distribution.copy_from_request(@request)
else
@distribution.line_items.build
@distribution.copy_from_donation(params[:donation_id], params[:storage_location_id])
@@ -179,6 +180,7 @@ def edit
if (!@distribution.complete? && @distribution.future?) ||
current_user.has_cached_role?(Role::ORG_ADMIN, current_organization)
@distribution.line_items.build if @distribution.line_items.size.zero?
+ @request = @distribution.request
@items = current_organization.items.active.alphabetized
@partner_list = current_organization.partners.alphabetized
@audit_warning = current_organization.audits
@@ -210,6 +212,7 @@ def update
flash.now[:error] = insufficient_error_message(result.error.message)
@distribution.line_items.build if @distribution.line_items.size.zero?
@distribution.initialize_request_items
+ @request = @distribution.request
@items = current_organization.items.active.alphabetized
@partner_list = current_organization.partners.alphabetized
@storage_locations = current_organization.storage_locations.active.alphabetized
@@ -292,7 +295,7 @@ def distribution_params
end
def request_id
- params.dig(:distribution, :request_attributes, :id)
+ params[:request_id] || params.dig(:distribution, :request_attributes, :id)
end
def daily_items(pick_ups)
diff --git a/app/models/distribution.rb b/app/models/distribution.rb
index 025c7fc35a..9c77866ab9 100644
--- a/app/models/distribution.rb
+++ b/app/models/distribution.rb
@@ -125,8 +125,7 @@ def initialize_request_items
end
end
- def copy_from_request(request_id)
- request = Request.find(request_id)
+ def copy_from_request(request)
self.request = request
self.organization_id = request.organization_id
self.partner_id = request.partner_id
diff --git a/app/views/distributions/_form.html.erb b/app/views/distributions/_form.html.erb
index da523a8d3b..1cdecf83be 100644
--- a/app/views/distributions/_form.html.erb
+++ b/app/views/distributions/_form.html.erb
@@ -11,6 +11,7 @@
<%= f.association :partner,
collection: @partner_list,
label: "Partner",
+ readonly: !!@request,
error: "Which partner is this distribution going to?" %>
diff --git a/docs/user_guide/bank/essentials_requests.md b/docs/user_guide/bank/essentials_requests.md
index 7add4be016..5a3af827ab 100644
--- a/docs/user_guide/bank/essentials_requests.md
+++ b/docs/user_guide/bank/essentials_requests.md
@@ -1,16 +1,19 @@
READY FOR REVIEW
-#Requests
-Requests are how you get the information on what items the partners need. (You may think of them as orders.)
+
+# Requests
+
+Requests are how you get the information on what items the partners need. (You may think of them as orders.)
The unfulfilled ones appear in your dashboard, but you can also manage them in the Requests area.
-For a more fulsome description of how the whole shebang works, see [Partner Management -- Request Distribution Cycle](pm_request_distribution_cycle.md).
+For a more fulsome description of how the whole shebang works, see [Partner Management -- Request Distribution Cycle](pm_request_distribution_cycle.md).
## Seeing your unfulfilled Requests
-We show the unfulfilled Requests in two places -- on the [dashboard](essentials_dashboard.md), and as part of the Requests list, which you access by clicking "Requests" in the left hand menu.
+
+We show the unfulfilled Requests in two places -- on the [dashboard](essentials_dashboard.md), and as part of the Requests list, which you access by clicking "Requests" in the left hand menu.

-On the Request list, the Requests are in order by the status (with pending first, then started, then fulfilled), then reverse chronological by date
+On the Request list, the Requests are in order by the status (with pending first, then started, then fulfilled), then reverse chronological by date
You can view or cancel any Request by using the buttons under "Actions"
To see a list of Requests, click on "Requests" in the left hand menu
@@ -18,12 +21,13 @@ This list is defaulted to a date range of the 60 days in the past to 30 days in
status, then reverse chronological (i.e. newest first).
The list contains:
+
- Date -- the date the Request was entered by the partner
- Request was sent by -- the name of the partner that sent the Request
- Request sender -- the user that sent the Request
-- #of Items (Request limit) -- the number of items in the Request, and, if you have entered it, the quota for the partner (see [Partners](getting_started_partners.md)
+- #of Items (Request limit) -- the number of items in the Request, and, if you have entered it, the quota for the partner (see [Partners](getting_started_partners.md)
- Comments -- the comments the partner entered on the Request
-- Status
+- Status
- pending -- haven't started fulfilling it yet
- started -- have started fulfilling, but haven't saved the resulting distribution
- fulfilled -- have created the distribution for this Request
@@ -31,26 +35,31 @@ The list contains:
- and the actions you can take on that Request
### Filtering your Requests
+
You can filter the Request list by:
+
- Item
- Partner
- Status
- Date range
Fill in the fields with the values you want to filter by, then click "filter"
-To reset to the defaults, click "Clear Filters"
+To reset to the defaults, click "Clear Filters"
## Product totals
+
You can find out how much of each product you'll need to fulfill the current filtered open (pending and started) Requests by clicking "Calculate Product Totals".

-This brings up a scrollable list showing the quantity of each Item you need to fulfill the Requests. It takes into account the current filters. Click the "x" in the top right corner of the list to close it.
+This brings up a scrollable list showing the quantity of each Item you need to fulfill the Requests. It takes into account the current filters. Click the "x" in the top right corner of the list to close it.

## Viewing a Request
+
To view a given Request, click "View" beside it in the Request list.

This brings up details of the Request including:
+
- Partner
- Date the Request was sent
- Who sent the Request
@@ -61,39 +70,42 @@ This brings up details of the Request including:
- Quantity
- If you are using [custom units](special_custom_units.md), those custom units will appear here.
- Total Inventory (across all Storage Locations)
-At the bottom of the screen are buttons letting you start to fulfill the Request, or to cancel it.
-
+ At the bottom of the screen are buttons letting you start to fulfill the Request, or to cancel it.
+ 
## Fulfilling a Request
-To fulfill a Request, bring up the Request list by clicking on "Requests" in the left-hand menu, then click on "view" beside the request, then scroll to the bottom of that screen and click "Fulfill request".
+
+To fulfill a Request, bring up the Request list by clicking on "Requests" in the left-hand menu, then click on "view" beside the request, then scroll to the bottom of that screen and click "Fulfill request".
That will bring you into a screen that allows you to specify the details for the distribution based on that Request -- you'll see a notice "request started".
-Fill in the remaining needed information. The fields include:
-- Partner (It would be rare indeed to change this)
+Fill in the remaining needed information. The fields include:
+
+- Partner (from the request, not editable)
- Distribution date and time (the scheduled pickup delivery or shipment date)
- Send email reminder the day before?
- Agency representative (defaulted to the user who sent the Request)
- Delivery method
- Pick up,
- - Delivery, or
+ - Delivery, or
- Shipped
- Shipping cost (if the delivery method is shipped)
-- From Storage Location (if you have chosen a default location for the Partner, or for your organization, this will be filled in)
+- From Storage Location (if you have chosen a default location for the Partner, or for your organization, this will be filled in)
- Comment
- For each Item in the Request
- The Item
- - When you have chosen the Storage Location, the quantity of this Item that is available at that Storage Location will appear here in parentheses.
+ - When you have chosen the Storage Location, the quantity of this Item that is available at that Storage Location will appear here in parentheses.
- A field for the quantity to be distributed
- - the requested amount.
+ - the requested amount.
- For any Item that has [custom units](special_custom_units.md), this will show both the amount and the unit
-You can remove any Item by clicking the associated "remove" button, and you can add more iIems, by clicking the "Add Another Item" button.
-
+ You can remove any Item by clicking the associated "remove" button, and you can add more iIems, by clicking the "Add Another Item" button.
+
When you have finished filling in the information, save the Distribution by clicking the "save" button.You'll see a page showing the details of the Distribution.
-If you have set the [Partner](getting_started_partners.md) to receive emails for distributions and reminders from the system
-the partner will be sent an email letting them know that their Request has been fulfilled. This will contain the text you have [customized](getting_started_customization.md), with an attachment showing the details of the distribution.
+If you have set the [Partner](getting_started_partners.md) to receive emails for distributions and reminders from the system
+the partner will be sent an email letting them know that their Request has been fulfilled. This will contain the text you have [customized](getting_started_customization.md), with an attachment showing the details of the distribution.

## Submitting a Request on Behalf of a Partner
+
Bank admins can submit a Request on behalf of a Partner by clicking the "New Quantity Request" button.

@@ -101,7 +113,8 @@ This will bring up a list of Partners to choose from. After selecting a Partner,

## Cancelling a Request
-To cancel a Request from the Requests list, click the "cancel" button beside it.
+
+To cancel a Request from the Requests list, click the "cancel" button beside it.

You can also cancel a Request from the single Request view by clicking the "cancel" button at the bottom of that page.
@@ -112,23 +125,24 @@ You will be prompted to provide a reason for the cancellation.
The Partner will receive an email notifying them of the cancellation.

-NOTE: This email goes to the Partner, rather than to the User who sent the request.
-
+NOTE: This email goes to the Partner, rather than to the User who sent the request.
## Exporting Requests
-To export the Requests from the Request list, click "Export Requests"
+
+To export the Requests from the Request list, click "Export Requests"

This will create a .csv file with the following information for each filtered Request:
+
- Date
- Requestor (partner)
- Status
- For each of the bank's items.
- the quantity requested
- Note: If you use custom units, there will be a column for each item/unit that is available to be requested.
+ Note: If you use custom units, there will be a column for each item/unit that is available to be requested.
## Printing unfulfilled Request picklists
-Finally, you can also print "picklists" for your unfulfilled Requests.
+Finally, you can also print "picklists" for your unfulfilled Requests.
This function produces a printable pdf file showing all the items requested for each of your unfulfilled Requests
Click "Print Unfulfilled Picklists" on your Requests list.
@@ -137,6 +151,4 @@ Here is a sample picklist:

-
-[Prior: Purchases](essentials_purchases.md) [Next: Distributions](essentials_distributions.md)
-
+[Prior: Purchases](essentials_purchases.md) [Next: Distributions](essentials_distributions.md)
diff --git a/spec/models/distribution_spec.rb b/spec/models/distribution_spec.rb
index ae05a333b6..496dcd8b33 100644
--- a/spec/models/distribution_spec.rb
+++ b/spec/models/distribution_spec.rb
@@ -284,7 +284,7 @@
create(:item_request, request: request, item_id: item1.id, quantity: 15)
create(:item_request, request: request, item_id: item2.id, quantity: 18)
distribution = Distribution.new
- distribution.copy_from_request(request.id)
+ distribution.copy_from_request(request)
expect(distribution.line_items.size).to eq 2
expect(distribution.line_items.first.quantity).to eq 15
expect(distribution.line_items.second.quantity).to eq 18
diff --git a/spec/requests/distributions_requests_spec.rb b/spec/requests/distributions_requests_spec.rb
index 2b35df1bd6..7414a14c27 100644
--- a/spec/requests/distributions_requests_spec.rb
+++ b/spec/requests/distributions_requests_spec.rb
@@ -322,6 +322,13 @@
expect(selectable_items).not_to include("Inactive Item")
end
+ it "disables the partner field when distribution is created from a request" do
+ get new_distribution_path(default_params)
+ page = Nokogiri::HTML(response.body)
+
+ expect(page.at_css("select#distribution_partner_id").classes).to include("readonly")
+ end
+
context "with org default but no partner default" do
it "selects org default" do
organization.update!(default_storage_location: storage_location.id)
@@ -392,6 +399,13 @@
# in the template
expect(page.css('select[name="distribution[line_items_attributes][1][item_id]"]')).not_to be_empty
end
+
+ it "should have partner select field enabled" do
+ get new_distribution_path({})
+ page = Nokogiri::HTML(response.body)
+
+ expect(page.at_css("select#distribution_partner_id").classes).not_to include("readonly")
+ end
end
end
end
@@ -662,6 +676,13 @@
expect(selectable_items).not_to include("Inactive Item")
end
+ it "should have partner select field enabled" do
+ get edit_distribution_path(id: distribution.id)
+ page = Nokogiri::HTML(response.body)
+
+ expect(page.at_css("select#distribution_partner_id").classes).not_to include("readonly")
+ end
+
context 'with units' do
let!(:request) {
create(:request,
@@ -715,6 +736,13 @@
expect(page.css('#distribution_line_items_attributes_2_quantity').attr('value').value).to eq('0')
end
+ it "disables the partner field when distribution is created from a request" do
+ get edit_distribution_path(id: distribution.id)
+ page = Nokogiri::HTML(response.body)
+
+ expect(page.at_css("select#distribution_partner_id").classes).to include("readonly")
+ end
+
context 'with no request' do
it 'should have everything enabled' do
request.destroy
diff --git a/spec/system/distribution_system_spec.rb b/spec/system/distribution_system_spec.rb
index c45a484fe8..11bd930ccd 100644
--- a/spec/system/distribution_system_spec.rb
+++ b/spec/system/distribution_system_spec.rb
@@ -615,7 +615,7 @@
it "sets the distribution id and fulfilled status on the request" do
items = storage_location.items.pluck(:id).sample(2)
request_items = [{ "item_id" => items[0], "quantity" => 10 }, { "item_id" => items[1], "quantity" => 10 }]
- @request = create :request, organization: organization, request_items: request_items
+ @request = create(:request, organization:, request_items:, partner:)
create(:item_request, request: @request, item_id: items[0], quantity: 10)
create(:item_request, request: @request, item_id: items[1], quantity: 10)
@@ -650,7 +650,7 @@
it "maintains the connection with the request even when there are initial errors" do
items = storage_location.items.pluck(:id).sample(2)
request_items = [{ "item_id" => items[0], "quantity" => 1000000 }, { "item_id" => items[1], "quantity" => 10 }]
- @request = create :request, organization: organization, request_items: request_items
+ @request = create(:request, organization:, request_items:, partner:)
create(:item_request, request: @request, item_id: items[0], quantity: 1000000)
create(:item_request, request: @request, item_id: items[1], quantity: 10)
diff --git a/spec/system/request_system_spec.rb b/spec/system/request_system_spec.rb
index 548f7f29ca..3c3e4ebdfd 100644
--- a/spec/system/request_system_spec.rb
+++ b/spec/system/request_system_spec.rb
@@ -4,8 +4,8 @@
let(:item1) { create(:item, name: "Good item") }
let(:item2) { create(:item, name: "Crap item") }
- let(:partner1) { create(:partner, name: "This Guy", email: "thisguy@example.com") }
- let(:partner2) { create(:partner, name: "That Guy", email: "ntg@example.com") }
+ let(:partner1) { create(:partner, organization:, name: "This Guy", email: "thisguy@example.com") }
+ let(:partner2) { create(:partner, organization:, name: "That Guy", email: "ntg@example.com") }
let!(:storage_location) { create(:storage_location, organization: organization) }
before do