Skip to content

Conversation

@awwaiid
Copy link
Collaborator

@awwaiid awwaiid commented May 11, 2025

First pass at removing request_item everywhere.

  • Main reads on the Bank's Request controller/view
  • Update distribution PDF to read from item_request
  • Update confirmation email to read from item_request
  • Fix specs to make the correct mock data

Comment on lines +34 to +38
@inventory = View::Inventory.new(@request.organization_id)
@default_storage_location = @request.partner.default_storage_location_id || @request.organization.default_storage_location
@location = StorageLocation.find_by(id: @default_storage_location)

@custom_units = Flipper.enabled?(:enable_packs) && @request.item_requests.any? { |item| item.request_unit }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These variables were previously being built directly in the view.


private

# TODO: remove the need to de-duplicate items in the request
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Going forward (for a while now), duplication isn't allowed when the request is created in the first place, so we don't need to merge things for the email anymore.

"Value/item",
"In-Kind Value Received",
"Packages"]]
inventory = View::Inventory.new(@distribution.organization_id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interestingly, this appears to already have not been used. This time rubocop noticed and had me remove it.

<td><%= item.quantity %></td>
<% if custom_units %>
<td><%= item.unit&.pluralize(item.quantity) %></td>
<td><%= item_request.item&.name || item_request.name %></td>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tries to look up the "current" item name, and then falls back to the cached item_request.name. We do this elsewhere also.

let(:mail) { RequestsConfirmationMailer.confirmation_email(request) }

let(:request_w_varied_quantities) { create(:request, :with_varied_quantities, organization: organization) }
let(:request_w_varied_quantities) { create(:request, :with_varied_quantities, :with_item_requests, organization: organization) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A lot of these factories now require :with_item_requests role; in a further PR I'll make that the default and then remove all of the instances of the param.

["Item 1", "", 50, "$1.00", "$50.00", "1"],
["Item 2", 30, 100, "$2.00", "$200.00", nil],
["Item 3", 50, "", "$3.00", nil, nil],
["Item 2", "30", 100, "$2.00", "$200.00", nil],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are surprisingly stored as strings; in the old one they ended up number-ified somewhere, but they are turned into strings in the PDF anyway so strings are fine.

@awwaiid awwaiid marked this pull request as ready for review May 11, 2025 15:48
@awwaiid awwaiid requested a review from dorner May 11, 2025 15:48
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Passes functional check. On to @dorner for technical comments.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Minor suggestion, otherwise looks good. 🎉

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

one last miss!

def name_with_unit(quantity_override = nil)
if Flipper.enabled?(:enable_packs) && request_unit.present?
"#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
"#{item_name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you forgot to use the new method here? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is one of the display helpers:

  • ItemRequest#item_name gives the item's name and falls back to the local copy
  • ItemRequest#quantity_with_units shows the qty and units but not the name
  • ItemRequest#name_with_unit shows the name and the unit but not qty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants