Browse Source

owning org id looks up serveral fields

bulk-upload-owning-org
Phil Lee 2 years ago
parent
commit
581178d8fc
  1. 10
      app/models/organisation.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/organisation.rb

@ -48,6 +48,16 @@ class Organisation < ApplicationRecord
validates :name, presence: { message: I18n.t("validations.organisation.name_missing") }
validates :provider_type, presence: { message: I18n.t("validations.organisation.provider_type_missing") }
def self.find_by_id_on_mulitple_fields(id)
return if id.nil?
if id.start_with?("ORG")
where(id: id[3..]).first
else
where(old_visible_id: id).first
end
end
def lettings_logs
LettingsLog.filter_by_organisation(self)
end

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

@ -115,7 +115,7 @@ class BulkUpload::Lettings::RowParser
attribute :field_108, :string
attribute :field_109, :string
attribute :field_110
attribute :field_111, :integer
attribute :field_111, :string
attribute :field_112, :string
attribute :field_113, :integer
attribute :field_114, :integer
@ -518,7 +518,7 @@ private
end
def owning_organisation
Organisation.find_by(old_visible_id: field_111)
Organisation.find_by_id_on_mulitple_fields(field_111)
end
def owning_organisation_id

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

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

Loading…
Cancel
Save