Browse Source

bulk upload schemes can use new core IDs

pull/1329/head
Phil Lee 3 years ago
parent
commit
45c76a894f
  1. 10
      app/models/scheme.rb
  2. 4
      app/services/bulk_upload/lettings/row_parser.rb
  3. 10
      spec/services/bulk_upload/lettings/row_parser_spec.rb

10
app/models/scheme.rb

@ -110,6 +110,16 @@ class Scheme < ApplicationRecord
enum arrangement_type: ARRANGEMENT_TYPE, _suffix: true enum arrangement_type: ARRANGEMENT_TYPE, _suffix: true
def self.find_by_id_on_mulitple_fields(id)
return if id.nil?
if id.start_with?("S")
where(id: id[1..]).first
else
where(old_visible_id: id).first
end
end
def id_to_display def id_to_display
"S#{id}" "S#{id}"
end end

4
app/services/bulk_upload/lettings/row_parser.rb

@ -8,7 +8,7 @@ class BulkUpload::Lettings::RowParser
attribute :field_1, :integer attribute :field_1, :integer
attribute :field_2 attribute :field_2
attribute :field_3 attribute :field_3
attribute :field_4, :integer attribute :field_4, :string
attribute :field_5, :integer attribute :field_5, :integer
attribute :field_6 attribute :field_6
attribute :field_7, :string attribute :field_7, :string
@ -964,6 +964,6 @@ private
end end
def scheme def scheme
@scheme ||= Scheme.find_by(old_visible_id: field_4) @scheme ||= Scheme.find_by_id_on_mulitple_fields(field_4)
end end
end end

10
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -620,6 +620,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
describe "#log" do describe "#log" do
describe "#scheme" do
context "when lookup is via id prefixed with S" do
let(:attributes) { { bulk_upload:, field_4: "S#{scheme.id}", field_111: owning_org } }
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
end
end
describe "#owning_organisation" do describe "#owning_organisation" do
context "when lookup is via id prefixed with ORG" do context "when lookup is via id prefixed with ORG" do
let(:attributes) { { bulk_upload:, field_111: "ORG#{owning_org.id}" } } let(:attributes) { { bulk_upload:, field_111: "ORG#{owning_org.id}" } }

Loading…
Cancel
Save