Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 2 additions & 15 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ 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:)
result = create.call

if result.success?
Expand Down Expand Up @@ -81,7 +77,7 @@ def update
return
end

if update_item
if update_item_and_request_units
redirect_to items_path, notice: "#{@item.name} updated!"
else
flash.now[:error] = "Something didn't work quite right -- try again? #{@item.errors.map { |error| "#{error.attribute}: #{error.message}" }}"
Expand Down Expand Up @@ -185,15 +181,6 @@ def request_unit_ids
params.require(:item).permit(request_unit_ids: []).fetch(:request_unit_ids, [])
end

# 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
end

def update_item_and_request_units
begin
Item.transaction do
Expand Down
13 changes: 6 additions & 7 deletions app/controllers/partners/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ 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

# 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
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/partners/item_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def item_name
end

def quantity_with_units
if Flipper.enabled?(:enable_packs) && request_unit.present?
if request_unit.present?
"#{quantity} #{request_unit.pluralize(quantity.to_i)}"
else
quantity
end
end

def name_with_unit(quantity_override = nil)
if Flipper.enabled?(:enable_packs) && request_unit.present?
if request_unit.present?
"#{item_name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}"
else
item_name
Expand Down
2 changes: 1 addition & 1 deletion app/models/view/request_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def location
end

def custom_units
Flipper.enabled?(:enable_packs) && request.item_requests.any? { |item| item.request_unit }
request.item_requests.any? { |item| item.request_unit }
end

def cancellable?
Expand Down
2 changes: 1 addition & 1 deletion app/pdfs/distribution_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def signature_lines_for(label)
end

def request_display_qty(item_request)
if Flipper.enabled?(:enable_packs) && item_request&.request_unit
if item_request&.request_unit
"#{item_request.quantity} #{item_request.request_unit.pluralize(item_request.quantity.to_i)}"
else
item_request&.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
18 changes: 8 additions & 10 deletions app/services/exports/export_request_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,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 Down
4 changes: 1 addition & 3 deletions app/services/item_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +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
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: 1 addition & 1 deletion app/views/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<%= f.input_field :package_size, class: "form-control", min: 0 %>
<% end %>

<% if Flipper.enabled?(:enable_packs) && current_organization.request_units.present? %>
<% if current_organization.request_units.present? %>
<%= 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 %>
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 @@ -12,10 +12,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 @@ -5,10 +5,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.blank? %>
<td><%= item_row.request_units.pluck(:name).join(', ') %></td>
<% end %>
<% unless current_organization.request_units.blank? %>
<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 @@ -154,24 +154,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
2 changes: 0 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,6 @@ def seed_quantity(item_name, organization, storage_location, quantity)
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "new_logo")
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
3 changes: 1 addition & 2 deletions docs/user_guide/bank/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ For each filtered Request,
- Date,
- Requestor (i.e. partner)
- Status, and
- the quantity of each Item requested.
- Note: If you have packs enabled (upcoming feature), there will be a column for each unit that you have enabled for each Item. Otherwise, one column per Item.
- the quantity of each Item requested. There will be a column for each unit that you have enabled for each Item.

## Storage Locations
### Navigating to export Storage Locations
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
end

context "request units" do
before(:each) { Flipper.enable(:enable_packs) }
let(:item) { create(:item, organization:) }
let(:unit) { create(:unit, organization:) }
it "should add new item's request units" do
Expand Down Expand Up @@ -168,7 +167,6 @@
end

it "should accept request_unit ids and create request_units" do
Flipper.enable(:enable_packs)
unit = create(:unit, organization: organization)
item_params[:item] = item_params[:item].merge({request_unit_ids: [unit.id]})
post :create, params: item_params
Expand Down
Loading
Loading