From 5d41f30824daa3d0dc927d05c8a88c3d458c2f1f Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 13 Sep 2023 12:45:12 +0100 Subject: [PATCH] feat: use kebab case org fields --- app/services/imports/lettings_logs_import_service.rb | 4 ++-- app/services/imports/logs_import_service.rb | 6 +++--- app/services/imports/sales_logs_field_import_service.rb | 2 +- app/services/imports/sales_logs_import_service.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index d40df0fc1..1d3a3c3c7 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -61,8 +61,8 @@ module Imports # Required fields for status complete or logic to work # Note: order matters when we derive from previous values (attributes parameter) attributes["startdate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR") - attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") - attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID") + attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "owner-institution-id") + attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "managing-institution-id") attributes["creation_method"] = creation_method(xml_doc) attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") diff --git a/app/services/imports/logs_import_service.rb b/app/services/imports/logs_import_service.rb index f7456a3fb..3b08f57ed 100644 --- a/app/services/imports/logs_import_service.rb +++ b/app/services/imports/logs_import_service.rb @@ -31,9 +31,9 @@ module Imports end def find_organisation_id(xml_doc, id_field) - old_visible_id = string_or_nil(xml_doc, id_field) - organisation = Organisation.find_by(old_visible_id:) - raise "Organisation not found with legacy ID #{old_visible_id}" if organisation.nil? + old_org_id = meta_field_value(xml_doc, id_field)&.strip.presence + organisation = Organisation.find_by(old_org_id:) + raise "Organisation not found with old org ID #{old_org_id}" if organisation.nil? organisation.id end diff --git a/app/services/imports/sales_logs_field_import_service.rb b/app/services/imports/sales_logs_field_import_service.rb index 2a08a7ccf..4cda93d9d 100644 --- a/app/services/imports/sales_logs_field_import_service.rb +++ b/app/services/imports/sales_logs_field_import_service.rb @@ -45,7 +45,7 @@ module Imports if record.owning_organisation_id.present? @logger.info("sales log #{record.id} has a value for owning_organisation_id, skipping update") else - owning_organisation_id = find_organisation_id(xml_doc, "OWNINGORGID") + owning_organisation_id = find_organisation_id(xml_doc, "owner-institution-id") record.update!(owning_organisation_id:) @logger.info("sales log #{record.id}'s owning_organisation_id value has been set to #{owning_organisation_id}") end diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index c57f2d16a..b406c1c8b 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -27,7 +27,7 @@ module Imports # Note: order matters when we derive from previous values (attributes parameter) attributes["saledate"] = compose_date(xml_doc, "DAY", "MONTH", "YEAR") || Time.zone.parse(field_value(xml_doc, "xmlns", "CompletionDate")) - attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") + attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "owner-institution-id") attributes["type"] = unsafe_string_as_integer(xml_doc, "DerSaleType") attributes["old_id"] = meta_field_value(xml_doc, "document-id") attributes["old_form_id"] = safe_string_as_integer(xml_doc, "Form")