Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
de7bbd1
Refactor item creation and update logic in ItemsController
yahyaelganyni1 Jul 7, 2025
5c47062
Refactor fetch_items method to simplify item unit fetching logic
yahyaelganyni1 Jul 7, 2025
460a58e
Simplify name_with_unit method by removing Flipper condition for requ…
yahyaelganyni1 Jul 7, 2025
4b5a1fc
Refactor ItemCreateService to always sync request units in call method
yahyaelganyni1 Jul 7, 2025
22a9528
Refactor OrganizationUpdateService to streamline request unit handling
yahyaelganyni1 Jul 7, 2025
127e577
Remove Flipper condition from has_custom_units method for simplified …
yahyaelganyni1 Jul 7, 2025
647a66d
Remove Flipper condition for request_units input in item form
yahyaelganyni1 Jul 9, 2025
5191b5c
Remove Flipper condition for displaying custom request units in item …
yahyaelganyni1 Jul 9, 2025
62b1e3b
Remove Flipper condition for displaying request units in item row
yahyaelganyni1 Jul 9, 2025
948cd64
Remove Flipper condition for displaying custom units in item show view
yahyaelganyni1 Jul 9, 2025
ed61876
Remove Flipper condition for displaying custom request units in organ…
yahyaelganyni1 Jul 9, 2025
365be4b
Remove Flipper condition for displaying custom request units in organ…
yahyaelganyni1 Jul 10, 2025
f6742e0
Remove Flipper condition for displaying request units in requests in …
yahyaelganyni1 Jul 10, 2025
70000bd
Remove Flipper condition for displaying request unit selection error …
yahyaelganyni1 Jul 10, 2025
f5e6f4f
Remove Flipper condition for displaying request unit selection
yahyaelganyni1 Jul 10, 2025
b83faeb
Remove Flipper condition for displaying request units in new request …
yahyaelganyni1 Jul 10, 2025
7b3943e
Remove Flipper condition for displaying request units in request items
yahyaelganyni1 Jul 10, 2025
86f5410
Remove Flipper condition for displaying request units in validation m…
yahyaelganyni1 Jul 10, 2025
2b560ad
Remove Flipper condition for displaying request units in show view an…
yahyaelganyni1 Jul 10, 2025
b901c82
Remove Flipper condition for displaying signature lines and request q…
yahyaelganyni1 Jul 10, 2025
a868447
Update DistributionPdf spec to include units in item quantities
yahyaelganyni1 Jul 10, 2025
b76d927
Refactor item request handling to remove Flipper conditions and ensur…
yahyaelganyni1 Jul 10, 2025
1c46d84
Merge branch 'rubyforgood:main' into 5251-remove-enable-packs
yahyaelganyni1 Jul 15, 2025
97b560e
Merge branch 'main' into 5251-remove-enable-packs
yahyaelganyni1 Jul 24, 2025
3a3c815
Enhance RequestsTotalItemsService specs to handle request_unit variat…
yahyaelganyni1 Jul 31, 2025
68d1ce4
Merge branch 'main' into 5251-remove-enable-packs
yahyaelganyni1 Jul 31, 2025
b15953b
Merge branch '5251-remove-enable-packs' of https://github.com/yahyael…
yahyaelganyni1 Jul 31, 2025
8828b0b
Fix quantity display in name_with_unit method and update test for zer…
yahyaelganyni1 Jul 31, 2025
ae3deff
Refactor organization request specs to remove flipper checks for cust…
yahyaelganyni1 Jul 31, 2025
c24e5a4
Remove Flipper checks for enable_packs feature across various specs a…
yahyaelganyni1 Jul 31, 2025
152e064
Remove unnecessary blank line in packs enabled context of picklists_p…
yahyaelganyni1 Jul 31, 2025
335ffc8
Remove context for packs off in requests system spec
yahyaelganyni1 Jul 31, 2025
af050e5
Merge branch 'main' into 5251-remove-enable-packs
yahyaelganyni1 Aug 2, 2025
2ac64c4
Refactor name_with_unit method for clarity and consistency in unit ha…
yahyaelganyni1 Aug 11, 2025
5edb9c8
Merge branch 'main' into 5251-remove-enable-packs
yahyaelganyni1 Aug 12, 2025
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
16 changes: 6 additions & 10 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def index
end

def create
create = if Flipper.enabled?(:enable_packs)
ItemCreateService.new(organization_id: current_organization.id, item_params: item_params, request_unit_ids:)
else
ItemCreateService.new(organization_id: current_organization.id, item_params: item_params)
end
create = ItemCreateService.new(
organization_id: current_organization.id,
item_params: item_params,
request_unit_ids: request_unit_ids
)
result = create.call

if result.success?
Expand Down Expand Up @@ -182,11 +182,7 @@ def request_unit_ids

# We need to update both the item and the request_units together and fail together
def update_item
if Flipper.enabled?(:enable_packs)
update_item_and_request_units
else
@item.save
end
update_item_and_request_units
end

def update_item_and_request_units
Expand Down
12 changes: 5 additions & 7 deletions app/controllers/partners/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ def partner_request_params

def fetch_items
@requestable_items = PartnerFetchRequestableItemsService.new(partner_id: partner.id).call
if Flipper.enabled?(:enable_packs)
# hash of (item ID => hash of (request unit name => request unit plural name))
item_ids = @requestable_items.to_h.values
if item_ids.present?
@item_units = Item.where(id: item_ids).to_h do |i|
[i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }]
end
# Packs are always enabled, so always fetch item units
item_ids = @requestable_items.to_h.values
if item_ids.present?
@item_units = Item.where(id: item_ids).to_h do |i|
[i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/partners/item_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def request_unit_is_supported
end

def name_with_unit(quantity_override = nil)
if Flipper.enabled?(:enable_packs) && request_unit.present?
if request_unit.present?
"#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
else
item&.name || name
Expand Down
4 changes: 1 addition & 3 deletions app/pdfs/distribution_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ def insert_signature_fields
else
move_down 20
end

signature_lines_for "Received By:"

move_down 20
signature_lines_for "Delivered By:"
end
Expand All @@ -291,7 +289,7 @@ def signature_lines_for(label)
end

def request_display_qty(request_item)
if Flipper.enabled?(:enable_packs) && request_item&.unit
if request_item&.unit
"#{request_item.quantity} #{request_item.unit.pluralize(request_item.quantity)}"
else
request_item&.quantity || ""
Expand Down
2 changes: 1 addition & 1 deletion app/pdfs/picklists_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def compute_and_render
end

def has_custom_units?(line_items)
Flipper.enabled?(:enable_packs) && line_items.any? { |line_item| line_item.request_unit }
line_items.any? { |line_item| line_item.request_unit }
end

def data_with_units(line_items)
Expand Down
28 changes: 17 additions & 11 deletions app/services/exports/export_request_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ def compute_item_headers
if item_request.item
item = item_request.item
item_names << item.name
if Flipper.enabled?(:enable_packs)
item.request_units.each do |unit|
item_names << "#{item.name} - #{unit.name.pluralize}"
end

# It's possible that the unit is no longer valid, so we'd
# add that individually
if item_request.request_unit.present?
item_names << "#{item.name} - #{item_request.request_unit.pluralize}"
end
item.request_units.each do |unit|
item_names << "#{item.name} - #{unit.name.pluralize}"
end

# It's possible that the unit is no longer valid, so we'd
# add that individually
if item_request.request_unit.present?
item_names << "#{item.name} - #{item_request.request_unit.pluralize}"
end
end
end
Expand All @@ -97,7 +95,15 @@ def build_row_data(request)
row += Array.new(item_headers.size, 0)

request.item_requests.each do |item_request|
item_name = item_request.item.present? ? item_request.name_with_unit(0) : DELETED_ITEMS_COLUMN_HEADER
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did this have to change?

item_name = if item_request.item.present?
if item_request.request_unit.present?
item_request.name_with_unit(0)
else
item_request.item.name
end
else
DELETED_ITEMS_COLUMN_HEADER
end
item_column_idx = headers_with_indexes[item_name]
row[item_column_idx] ||= 0
row[item_column_idx] += item_request.quantity.to_i
Expand Down
5 changes: 1 addition & 4 deletions app/services/item_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def initialize(organization_id:, item_params:, request_unit_ids: [])
def call
new_item = organization.items.new(item_params)
new_item.save!
if Flipper.enabled?(:enable_packs)
new_item.sync_request_units!(@request_unit_ids)
end

new_item.sync_request_units!(@request_unit_ids)
Result.new(value: new_item)
rescue StandardError => e
Result.new(error: e)
Expand Down
14 changes: 6 additions & 8 deletions app/services/organization_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ def update(organization, params)
org_params["partner_form_fields"] = org_params["partner_form_fields"].compact_blank
end

if Flipper.enabled?(:enable_packs)
request_unit_names = org_params[:request_unit_names] || []
# Find or create units for the organization
request_unit_ids = request_unit_names.compact_blank.map do |request_unit_name|
Unit.find_or_create_by(organization: organization, name: request_unit_name).id
end
org_params.delete(:request_unit_names)
org_params[:request_unit_ids] = request_unit_ids
request_unit_names = org_params[:request_unit_names] || []
# Find or create units for the organization
request_unit_ids = request_unit_names.compact_blank.map do |request_unit_name|
Unit.find_or_create_by(organization: organization, name: request_unit_name).id
end
org_params.delete(:request_unit_names)
org_params[:request_unit_ids] = request_unit_ids

result = organization.update(org_params)

Expand Down
2 changes: 0 additions & 2 deletions app/views/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
<%= f.input_field :package_size, class: "form-control", min: 0 %>
<% end %>

<% if Flipper.enabled?(:enable_packs) %>
<%= f.input :request_units, label: "Additional Custom Request Units" do %>
<%= f.association :request_units, as: :check_boxes, collection: current_organization.request_units, checked: selected_item_request_units(@item), label_method: :name, value_method: :id, class: "form-check-input" %>
<% end %>
<% end %>

<%= f.input :visible, label: "Item is Visible to Partners?", wrapper: :input_group do %>
<%= f.check_box :visible_to_partners, {class: "input-group-text", id: "visible_to_partners"}, "true", "false" %>
Expand Down
6 changes: 2 additions & 4 deletions app/views/items/_item_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
<th>Add. Info</th>
<th class="text-right">Quantity Per Individual</th>
<th class="text-right">Fair Market Value (per item)</th>
<% if Flipper.enabled?(:enable_packs) %>
<% unless current_organization.request_units.empty? %>
<th>Custom Request Units</th>
<% end %>
<% unless current_organization.request_units.empty? %>
<th>Custom Request Units</th>
<% end %>
<th class="text-right">Actions</th>
</tr>
Expand Down
6 changes: 2 additions & 4 deletions app/views/items/_item_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
<td><%= truncate item_row.additional_info, length: 25 %></td>
<td class="text-right"> <%= item_row.distribution_quantity %></td>
<td class="numeric"><%= dollar_value(item_row.value_in_cents) %></td>
<% if Flipper.enabled?(:enable_packs) %>
<% unless current_organization.request_units.empty? %>
<td><%= item_row.request_units.pluck(:name).join(', ') %></td>
<% end %>
<% unless current_organization.request_units.empty? %>
<td><%= item_row.request_units.pluck(:name).join(', ') %></td>
<% end %>
<td class="text-right">
<%= view_button_to item_path(item_row) %>
Expand Down
8 changes: 3 additions & 5 deletions app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@
<td><%= @item.package_size || 0 %></td>
</tr>
<tr>
<% if Flipper.enabled?(:enable_packs) %>
<th>Custom Units</th>
<% item_units = @item.request_units&.pluck("item_units.name") %>
<td><%= item_units&.join("; ") %></td>
<% end %>
<th>Custom Units</th>
<% item_units = @item.request_units&.pluck("item_units.name") %>
<td><%= item_units&.join("; ") %></td>
</tr>
<tr>
<th>Item is visible to partners</th>
Expand Down
30 changes: 14 additions & 16 deletions app/views/organizations/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,22 @@
<%= humanize_boolean(@organization.enable_quantity_based_requests) %>
</p>
</div>
<% if Flipper.enabled?(:enable_packs) %>
<div>
<h6 class="font-weight-bold">Custom Request units used (please use singular form -- e.g. pack, not packs)</h6>
<p>
<% if @organization.request_units.length > 0 %>
<% @organization.request_units.map do |unit| %>
<%= fa_icon "angle-right" %>
<span>
<%= unit.name.titlecase %>
</span> <br>
<% end %>
<% else %>
<div>
<h6 class="font-weight-bold">Custom Request units used (please use singular form -- e.g. pack, not packs)</h6>
<p>
<% if @organization.request_units.length > 0 %>
<% @organization.request_units.map do |unit| %>
<%= fa_icon "angle-right" %>
<span> None </span>
<span>
<%= unit.name.titlecase %>
</span> <br>
<% end %>
</p>
</div>
<% end %>
<% else %>
<%= fa_icon "angle-right" %>
<span> None </span>
<% end %>
</p>
</div>
<hr>

<h4>Other emails</h4>
Expand Down
36 changes: 17 additions & 19 deletions app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,23 @@
<%= f.input :enable_child_based_requests, label: 'Enable Partners to make child-based Requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :enable_individual_requests, label: 'Enable Partners to make Requests by indicating number of individuals needing each Item?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :enable_quantity_based_requests, label: 'Enable Partners to make quantity-based Requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<% if Flipper.enabled?(:enable_packs) %>
<%= label_tag "organization[request_unit_names]", 'Custom request units used. Please use singular form -- e.g. pack, not packs. There will be a default "unit" entry provided.' %>
<%= select_tag(
"organization[request_unit_names]",
options_from_collection_for_select(
current_organization.request_units,
'name',
'name',
->(_) { true } # Select all of the current request units
),
{
multiple: true,
class: 'form-control custom-select',
'data-controller': 'select2',
'data-select2-hide-dropdown-value': true,
'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}'
}
) %>
<% end %>
<%= label_tag "organization[request_unit_names]", 'Custom request units used. Please use singular form -- e.g. pack, not packs. There will be a default "unit" entry provided.' %>
<%= select_tag(
"organization[request_unit_names]",
options_from_collection_for_select(
current_organization.request_units,
'name',
'name',
->(_) { true } # Select all of the current request units
),
{
multiple: true,
class: 'form-control custom-select',
'data-controller': 'select2',
'data-select2-hide-dropdown-value': true,
'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}'
}
) %>
<hr>

<h4>Other emails</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<td class="p-4 d-flex flex-wrap">
<% request.item_requests.each do |item_request| %>
<span class="p-1 mr-1 mb-2 lg:mb-0 border border-dark rounded-1">
<% if Flipper.enabled?(:enable_packs) && item_request.request_unit %>
<% if item_request.request_unit %>
<%= pluralize(item_request.quantity, item_request.request_unit) %>
<% else %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/requests/_error.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h3 class='text-4xl font-extrabold'>Oops! Something went wrong with your Request</h3>
<p class='text-lg font-bold'>
Ensure each line item has a item selected AND a quantity greater than 0.
<% if Flipper.enabled?(:enable_packs) && (current_partner&.organization || current_organization).request_units.any? %>
<% if (current_partner&.organization || current_organization).request_units.any? %>
Please ensure a single unit is selected for each item that supports it.
<% end %>
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/requests/_item_request.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= field.number_field :quantity, label: false, step: 1, min: 1, class: 'form-control' %>
</td>

<% if Flipper.enabled?(:enable_packs) && (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %>
<% if (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %>
<td>
<%= field.label :request_unit, "Unit", {class: 'sr-only'} %>
<%= field.select :request_unit, [], {include_blank: 'units'},
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<tr>
<th>Item Requested</th>
<th>Quantity</th>
<% if Flipper.enabled?(:enable_packs) && (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %>
<% if (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %>
<th>Units (if applicable)</th>
<% end %>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<% @partner_request.item_requests.each do |item| %>
<li>
<%= item.name %> - <%= item.quantity %>
<% if Flipper.enabled?(:enable_packs) && item.request_unit %>
<% if item.request_unit %>
<%= item.request_unit.pluralize(item.quantity.to_i) %>
<% end %>
</li>
Expand Down
4 changes: 2 additions & 2 deletions app/views/partners/requests/validate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tr>
<th>Item Name</th>
<th>Total Items</th>
<% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %>
<% if @partner_request.item_requests.any?( &:request_unit ) %>
<th>Units</th>
<% end %>
</tr>
Expand All @@ -21,7 +21,7 @@
<tr>
<td><%= line_item.name %></td>
<td><%= line_item.quantity %></td>
<% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %>
<% if @partner_request.item_requests.any?( &:request_unit ) %>
<td><%= line_item.request_unit&.pluralize(line_item.quantity.to_i) %></td>
<% end %>
</tr>
Expand Down
3 changes: 1 addition & 2 deletions app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<tr>
<th>Item</th>
<th>Quantity</th>
<% custom_units = Flipper.enabled?(:enable_packs) &&
@request.item_requests.any? { |item| item.request_unit } %>
<% custom_units = @request.item_requests.any? { |item| item.request_unit } %>
<% if custom_units %>
<th>Units (if applicable)</th>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ul>
<% @request_items.each do |item| %>
<li><%= item['name'] %> -
<% if Flipper.enabled?(:enable_packs) && item['unit'] %>
<% if item['unit'] %>
<%= pluralize(item['quantity'] || item['person_count'], item['unit']) %>
<% else %>
<%= item['quantity'] || item['person_count'] %>
Expand Down
4 changes: 1 addition & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def seed_random_item_with_name(organization, name)
receives_essentials_from_other: Faker::Lorem.sentence,
)
end

if p.partials_to_show.include? "organizational_capacity"
profile.update(
client_capacity: Faker::Lorem.sentence,
Expand Down Expand Up @@ -1111,8 +1111,6 @@ def seed_quantity(item_name, organization, storage_location, quantity)
Flipper.enable(:read_events)
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "partner_step_form")
Flipper.enable(:partner_step_form)
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "enable_packs")
Flipper.enable(:enable_packs)
# ----------------------------------------------------------------------------
# Account Requests
# ----------------------------------------------------------------------------
Expand Down
Loading