Browse Source

CLDC-2504 Add org select to sales if merged (#1830)

* feat: wip update sales org select

* feat: update routing and hidden in check answers methods

* feat: set sales org id as derived

* feat: update tests

* refactor: linting

* feat: update tests and radio options

* feat: update test

* feat: add value helper test for non-constant value question

* refactor: lint

* feat: freeze time in unrelated test

* refactor: linting

* feat: wip commit

* feat: tidy up active readouts

* feat: revert previous commits

* feat: put merge orgs behaviour behind feature flag

* feat: put merge orgs behaviour behind feature flag

* refactor: lint

* refactor: simplify

* feat: add one more feature toggle
pull/1819/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
ab55b67e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/form/lettings/pages/stock_owner.rb
  2. 6
      app/models/form/lettings/questions/stock_owner.rb
  3. 5
      app/models/form/sales/pages/organisation.rb
  4. 18
      app/models/form/sales/questions/owning_organisation_id.rb

8
app/models/form/lettings/pages/stock_owner.rb

@ -14,10 +14,14 @@ class Form::Lettings::Pages::StockOwner < ::Form::Page
return false unless current_user
return true if current_user.support?
stock_owners = current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
stock_owners = if FeatureToggle.merge_organisations_enabled?
current_user.organisation.stock_owners + current_user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
current_user.organisation.stock_owners
end
if current_user.organisation.holds_own_stock?
if current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
if FeatureToggle.merge_organisations_enabled? && current_user.organisation.absorbed_organisations.any?(&:holds_own_stock?)
return true
end
return true if stock_owners.count >= 1

6
app/models/form/lettings/questions/stock_owner.rb

@ -49,7 +49,11 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
def hidden_in_check_answers?(_log, user = nil)
return false if user.support?
stock_owners = user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
stock_owners = if FeatureToggle.merge_organisations_enabled?
user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
else
user.organisation.stock_owners
end
if user.organisation.holds_own_stock?
stock_owners.count.zero?

5
app/models/form/sales/pages/organisation.rb

@ -11,6 +11,8 @@ class Form::Sales::Pages::Organisation < ::Form::Page
end
def routed_to?(_log, current_user)
if FeatureToggle.merge_organisations_enabled?
return false unless current_user
return true if current_user.support?
@ -24,5 +26,8 @@ class Form::Sales::Pages::Organisation < ::Form::Page
end
false
else
!!current_user&.support?
end
end
end

18
app/models/form/sales/questions/owning_organisation_id.rb

@ -11,6 +11,8 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
answer_opts = { "" => "Select an option" }
return answer_opts unless ActiveRecord::Base.connected?
if FeatureToggle.merge_organisations_enabled?
return answer_opts unless user
return answer_opts unless log
@ -44,6 +46,12 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
answer_opts
else
Organisation.select(:id, :name).each_with_object(answer_opts) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
end
end
end
def displayed_answer_options(log, user = nil)
@ -57,10 +65,11 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
def derived?
true
true if FeatureToggle.merge_organisations_enabled?
end
def hidden_in_check_answers?(_log, user = nil)
if FeatureToggle.merge_organisations_enabled?
return false if user.support?
stock_owners = user.organisation.stock_owners + user.organisation.absorbed_organisations.where(holds_own_stock: true)
@ -70,6 +79,9 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
else
stock_owners.count <= 1
end
else
!current_user.support?
end
end
def enabled
@ -79,7 +91,11 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
private
def selected_answer_option_is_derived?(_log)
if FeatureToggle.merge_organisations_enabled?
true
else
false
end
end
def merged_organisation_label(name, merge_date)

Loading…
Cancel
Save