Skip to content

Commit b298f9c

Browse files
committed
Factor out item request name and qty/units helper
1 parent e83b14d commit b298f9c

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

app/models/partners/item_request.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,24 @@ def request_unit_is_supported
3636
end
3737
end
3838

39+
# Usually the item_name, but fall back to our local copy
40+
def item_name
41+
item&.name || name
42+
end
43+
44+
def quantity_with_units
45+
if Flipper.enabled?(:enable_packs) && request_unit.present?
46+
"#{quantity} #{request_unit.pluralize(quantity.to_i)}"
47+
else
48+
quantity
49+
end
50+
end
51+
3952
def name_with_unit(quantity_override = nil)
4053
if Flipper.enabled?(:enable_packs) && request_unit.present?
41-
"#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
54+
"#{item_name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
4255
else
43-
item&.name || name
56+
item_name
4457
end
4558
end
4659
end

app/views/requests/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<tbody>
8080
<% @item_requests.each do |item_request| %>
8181
<tr>
82-
<td><%= item_request.item&.name || item_request.name %></td>
82+
<td><%= item_request.item_name %></td>
8383
<td><%= item_request.quantity %></td>
8484
<% if @custom_units %>
8585
<td><%= item_request.request_unit&.pluralize(item_request.quantity.to_i) %></td>

app/views/requests_confirmation_mailer/confirmation_email.html.erb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
<p>This email confirms that <%= @organization.name %> has received a request<%= " submitted by #{@requester_user_name}" if @requester_user_name.present? %> for:</p>
44
<ul>
55
<% @item_requests.each do |item_request| %>
6-
<li><%= item_request.item&.name || item_request.name %> -
7-
<% if Flipper.enabled?(:enable_packs) && item_request.request_unit.present? %>
8-
<%= pluralize(item_request.quantity.to_i, item_request.request_unit) %>
9-
<% else %>
10-
<%= item_request.quantity %>
11-
<% end %>
12-
</li>
6+
<li><%= item_request.item_name %> - <%= item_request.quantity_with_units %></li>
137
<% end %>
148
</ul>
159

app/views/requests_confirmation_mailer/confirmation_email.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hello <%= @partner.name %>,
22

33
This email confirms that <%= @organization.name %> has received a request<%= " submitted by #{@requester_user_name}" if @requester_user_name.present? %> for:
44
<% @item_requests.each do |item_request| %>
5-
<%= item_request.item&.name || item_request.name %> - <%= item_request.quantity %>
5+
<%= item_request.item_name %> - <%= item_request.quantity_with_units %>
66
<% end %>
77

88
You will receive a notification when a distribution has been created of the pick-up time and date.

0 commit comments

Comments
 (0)