Skip to content

Commit

Permalink
Disable changing partner when creating distribution from request (#5029)
Browse files Browse the repository at this point in the history
* Disable changing partner when creating distribution from request

* Reformat docs file

* Update user docs

* Disable changing partner when editing distributions from requests
  • Loading branch information
coalest authored Feb 21, 2025
1 parent 635d83e commit 5b32c90
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 43 deletions.
13 changes: 8 additions & 5 deletions app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/views/distributions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<%= f.association :partner,
collection: @partner_list,
label: "Partner",
readonly: !!@request,
error: "Which partner is this distribution going to?" %>

<div class='w-72'>
Expand Down
74 changes: 43 additions & 31 deletions docs/user_guide/bank/essentials_requests.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,65 @@
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.
![navigation to Request list](images/essentials/requests/essentials_requests_navigation.png)

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

This list is defaulted to a date range of the 60 days in the past to 30 days in the future (though there will be no future-dated Requests), all items, all partners, and all statuses, ordered by
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
- discarded -- have cancelled the Request
- 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".

![Navigational screenshot, product totals](images/essentials/requests/essentials_requests_product_totals_navigation.png)
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.
![Product totals list](images/essentials/requests/essentials_requests_product_totals.png)

## Viewing a Request

To view a given Request, click "View" beside it in the Request list.
![Navigation to Request view](images/essentials/requests/essentials_requests_view_navigation.png)
This brings up details of the Request including:

- Partner
- Date the Request was sent
- Who sent the Request
Expand All @@ -61,47 +70,51 @@ 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.
![Request view](images/essentials/requests/essentials_requests_view.png)
At the bottom of the screen are buttons letting you start to fulfill the Request, or to cancel it.
![Request view](images/essentials/requests/essentials_requests_view.png)

## 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.
![Example distribution printout](images/essentials/distributions/essentials_distributions_printout.png)

## 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.
![New Request button](images/essentials/requests/essentials_requests_new_request_button.png)

This will bring up a list of Partners to choose from. After selecting a Partner, the details for the Request can be entered.
![New Request details](images/essentials/requests/essentials_requests_new_request_details.png)

## 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.
![navigation to cancel Request](images/essentials/requests/essentials_requests_cancel_navigation.png)
You can also cancel a Request from the single Request view by clicking the "cancel" button at the bottom of that page.

Expand All @@ -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.
![cancel Request email](images/essentials/requests/essentials_requests_cancel_email.png)

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"
![Export Requests navigation](images/essentials/requests/essentials_requests_export_navigation.png)
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.
Expand All @@ -137,6 +151,4 @@ Here is a sample picklist:

![Picklist](images/essentials/requests/essentials_requests_picklist.png)


[Prior: Purchases](essentials_purchases.md) [Next: Distributions](essentials_distributions.md)

[Prior: Purchases](essentials_purchases.md) [Next: Distributions](essentials_distributions.md)
2 changes: 1 addition & 1 deletion spec/models/distribution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/requests/distributions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/system/distribution_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions spec/system/request_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b32c90

Please sign in to comment.