@ -28,43 +28,36 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
end
end
end
if FeatureToggle . merge_organisations_enabled?
if log . owning_organisation_id . present?
if log . owning_organisation_id . present?
answer_opts [ log . owning_organisation . id ] = log . owning_organisation . name
answer_opts [ log . owning_organisation . id ] = log . owning_organisation . name
end
end
recently_absorbed_organisations = user . organisation . absorbed_organisations . merged_during_open_collection_period
recently_absorbed_organisations = user . organisation . absorbed_organisations . merged_during_open_collection_period
if ! user . support? && user . organisation . holds_own_stock?
if ! user . support? && user . organisation . holds_own_stock?
answer_opts [ user . organisation . id ] = if recently_absorbed_organisations . exists? && user . organisation . available_from . present?
answer_opts [ user . organisation . id ] = if recently_absorbed_organisations . exists? && user . organisation . available_from . present?
" #{ user . organisation . name } (Your organisation, active as of #{ user . organisation . available_from . to_fs ( :govuk_date ) } ) "
" #{ user . organisation . name } (Your organisation, active as of #{ user . organisation . available_from . to_fs ( :govuk_date ) } ) "
else
else
" #{ user . organisation . name } (Your organisation) "
" #{ user . organisation . name } (Your organisation) "
end
end
end
end
if user . support?
if user . support?
Organisation . where ( holds_own_stock : true ) . find_each do | org |
Organisation . where ( holds_own_stock : true ) . find_each do | org |
if org . merge_date . present?
if org . merge_date . present?
answer_opts [ org . id ] = " #{ org . name } (inactive as of #{ org . merge_date . to_fs ( :govuk_date ) } ) " if org . merge_date > = FormHandler . instance . start_date_of_earliest_open_for_editing_collection_period
answer_opts [ org . id ] = " #{ org . name } (inactive as of #{ org . merge_date . to_fs ( :govuk_date ) } ) " if org . merge_date > = FormHandler . instance . start_date_of_earliest_open_for_editing_collection_period
elsif org . absorbed_organisations . merged_during_open_collection_period . exists? && org . available_from . present?
elsif org . absorbed_organisations . merged_during_open_collection_period . exists? && org . available_from . present?
answer_opts [ org . id ] = " #{ org . name } (active as of #{ org . available_from . to_fs ( :govuk_date ) } ) "
answer_opts [ org . id ] = " #{ org . name } (active as of #{ org . available_from . to_fs ( :govuk_date ) } ) "
else
else
answer_opts [ org . id ] = org . name
answer_opts [ org . id ] = org . name
end
end
else
recently_absorbed_organisations . each do | absorbed_org |
answer_opts [ absorbed_org . id ] = merged_organisation_label ( absorbed_org . name , absorbed_org . merge_date ) if absorbed_org . holds_own_stock?
end
end
end
end
answer_opts
else
else
Organisation . select ( :id , :name ) . each_with_object ( answer_opts ) do | organisation , hsh |
recently_absorbed_organisations . each do | absorbed_org |
hsh [ organisation . id ] = organisation . name
answer_opts [ absorbed_org . id ] = merged_organisation_label ( absorbed_org . name , absorbed_org . merge_date ) if absorbed_org . holds_own_stock?
hsh
end
end
end
end
answer_opts
end
end
def displayed_answer_options ( log , user = nil )
def displayed_answer_options ( log , user = nil )
@ -82,18 +75,14 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
end
def hidden_in_check_answers? ( _log , user = nil )
def hidden_in_check_answers? ( _log , user = nil )
if FeatureToggle . merge_organisations_enabled?
return false if user . support?
return false if user . support?
stock_owners = user . organisation . stock_owners + user . organisation . absorbed_organisations . where ( holds_own_stock : true )
stock_owners = user . organisation . stock_owners + user . organisation . absorbed_organisations . where ( holds_own_stock : true )
if user . organisation . holds_own_stock?
if user . organisation . holds_own_stock?
stock_owners . count . zero?
stock_owners . count . zero?
else
stock_owners . count < = 1
end
else
else
! current_user . support?
stock_owners . count < = 1
end
end
end
end
@ -104,11 +93,7 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
private
private
def selected_answer_option_is_derived? ( _log )
def selected_answer_option_is_derived? ( _log )
if FeatureToggle . merge_organisations_enabled?
true
true
else
false
end
end
end
def merged_organisation_label ( name , merge_date )
def merged_organisation_label ( name , merge_date )