Browse Source

Do not show stock owners in sales logs owning org options

pull/1821/head
Kat 3 years ago
parent
commit
1341cd51dd
  1. 5
      app/models/form/sales/questions/owning_organisation_id.rb
  2. 27
      spec/models/form/sales/questions/owning_organisation_id_spec.rb

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

@ -27,15 +27,12 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
end
end
user_organisation_options = user.support? ? Organisation.where(holds_own_stock: true) : user.organisation.stock_owners
user_organisation_options = user.support? ? Organisation.where(holds_own_stock: true) : Organisation.none
user_answer_options = user_organisation_options.pluck(:id, :name).to_h
unless user.support?
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?
absorbed_org.stock_owners.each do |stock_owner|
user_answer_options[stock_owner.id] = merged_organisation_label(stock_owner.name, absorbed_org.merge_date)
end
end
end

27
spec/models/form/sales/questions/owning_organisation_id_spec.rb

@ -70,31 +70,13 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
"" => "Select an option",
owning_org_1.id => "Owning org 1",
user.organisation.id => "User org (Your organisation)",
owning_org_2.id => "Owning org 2",
}
end
it "shows current stock owner at top, followed by user's org (with hint), followed by the stock owners of the user's org" do
it "does not show stock owner" do
user.organisation.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
context "when the owning-managing organisation relationship is deleted" do
let(:options) do
{
"" => "Select an option",
user.organisation.id => "User org (Your organisation)",
owning_org_2.id => "Owning org 2",
}
end
it "doesn't remove the housing provider from the list of allowed housing providers" do
log.update!(owning_organisation: owning_org_2)
expect(question.displayed_answer_options(log, user)).to eq(options)
org_rel.destroy!
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
end
context "when user's org doesn't own stock" do
@ -102,11 +84,10 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
{
"" => "Select an option",
owning_org_1.id => "Owning org 1",
owning_org_2.id => "Owning org 2",
}
end
it "shows current stock owner at top, followed by the stock owners of the user's org" do
it "shows current log owner" do
user.organisation.update!(holds_own_stock: false)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -120,7 +101,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
user.organisation.id => "User org (Your organisation, active as of 2 February 2021)",
owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
owning_org_2.id => "Owning org 2",
}
end
@ -142,7 +122,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
user.organisation.id => "User org (Your organisation, active as of 2 February 2021)",
owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
owning_org_2.id => "Owning org 2 (inactive as of 2 February 2023)",
}
end
@ -152,7 +131,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
end
it "shows merged organisations stock owners as options" do
it "does not show merged organisations stock owners as options" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end

Loading…
Cancel
Save