From 581178d8fc715e361d0b2aaef1324bf42d1a6b24 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 16 Feb 2023 11:54:49 +0000 Subject: [PATCH] owning org id looks up serveral fields --- app/models/organisation.rb | 10 ++++++++++ app/services/bulk_upload/lettings/row_parser.rb | 4 ++-- spec/services/bulk_upload/lettings/row_parser_spec.rb | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 3e8f9cb26..fd8891961 100644 --- a/app/models/organisation.rb +++ b/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 diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index 9c7d0e1ed..9ad0599af 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/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 diff --git a/spec/services/bulk_upload/lettings/row_parser_spec.rb b/spec/services/bulk_upload/lettings/row_parser_spec.rb index b8c18923b..50386581b 100644 --- a/spec/services/bulk_upload/lettings/row_parser_spec.rb +++ b/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 } }