Custom request units used (please use singular form -- e.g. pack, not packs) | +
---|
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 4ab62d3ac4..4c9f2c09c8 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -100,7 +100,8 @@ def organization_params :ytd_on_distribution_printout, :one_step_partner_invite, :hide_value_columns_on_receipt, :hide_package_column_on_receipt, :signature_for_distribution_pdf, - partner_form_fields: [] + partner_form_fields: [], + request_units_attributes: [:id, :organization_id, :name] ) end diff --git a/app/models/organization.rb b/app/models/organization.rb index cd03a56f2a..d8f46221a6 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -135,7 +135,7 @@ def flipper_id has_one_attached :logo - accepts_nested_attributes_for :users, :account_request + accepts_nested_attributes_for :users, :account_request, :request_units include Geocodable diff --git a/app/models/unit.rb b/app/models/unit.rb index 53527345ec..979f03b7be 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -10,4 +10,6 @@ # class Unit < ApplicationRecord belongs_to :organization + # This validation prevent duplicates except when creating two units of the same name at the same time (on the organization update page) + validates :name, uniqueness: {scope: :organization} end diff --git a/app/services/organization_update_service.rb b/app/services/organization_update_service.rb index 0b5b3c72c6..46287344ea 100644 --- a/app/services/organization_update_service.rb +++ b/app/services/organization_update_service.rb @@ -15,7 +15,17 @@ def update(organization, params) if params.has_key?("partner_form_fields") params["partner_form_fields"].delete_if { |field| field == "" } end - result = organization.update(params) + + if Flipper.enabled?(:enable_packs) + # Needs logic to keep units that are in use + units = params[:request_units_attributes].to_h.values + new_units = units.map { |unit| Unit.find_or_initialize_by(unit) } + result = organization.update(params.except(:request_units_attributes)) + organization.request_units = new_units + else + result = organization.update(params) + end + return false unless result update_partner_flags(organization) true diff --git a/app/views/organizations/_details.html.erb b/app/views/organizations/_details.html.erb index d92788f59f..90dc479f6f 100644 --- a/app/views/organizations/_details.html.erb +++ b/app/views/organizations/_details.html.erb @@ -125,6 +125,24 @@ <%= humanize_boolean(@organization.distribute_monthly) %>
+ <% if Flipper.enabled?(:enable_packs) %> +
+ <% if @organization.request_units.length > 0 %>
+ <% @organization.request_units.map do |unit| %>
+ <%= fa_icon "angle-right" %>
+
+ <%= unit.name.titlecase %>
+
+ <% end %>
+ <% else %>
+ <%= fa_icon "angle-right" %>
+ None
+ <% end %>
+
diff --git a/app/views/organizations/edit.html.erb b/app/views/organizations/edit.html.erb index 4c7cc0928d..a2696c05ce 100644 --- a/app/views/organizations/edit.html.erb +++ b/app/views/organizations/edit.html.erb @@ -40,7 +40,9 @@
Custom request units used (please use singular form -- e.g. pack, not packs) | +
---|