From faa2b7898426c192dbfaadfa0197a18592ff6903 Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 17 Feb 2025 08:10:30 +0000 Subject: [PATCH] Update sales export fields --- .../exports/sales_log_export_constants.rb | 169 ++++++----------- .../exports/sales_log_export_service.rb | 75 +++++++- spec/fixtures/exports/sales_log.xml | 174 ++++++------------ spec/fixtures/exports/sales_log_2024.xml | 174 ++++++------------ .../exports/sales_log_export_service_spec.rb | 4 + 5 files changed, 257 insertions(+), 339 deletions(-) diff --git a/app/services/exports/sales_log_export_constants.rb b/app/services/exports/sales_log_export_constants.rb index 4d5400758..d286b40ac 100644 --- a/app/services/exports/sales_log_export_constants.rb +++ b/app/services/exports/sales_log_export_constants.rb @@ -9,181 +9,130 @@ module Exports::SalesLogExportConstants EXPORT_FIELDS = Set["id", "status", - "saledate", - "created_at", - "updated_at", - "owning_organisation_id", - "assigned_to_id", + "day", + "month", + "year", + "duplicate_set_id", + "createddate", + "uploaddate", + "owningorgid", + "owningorgname", + "maningorgid", + "maningorgname", + "username", + "usernameid", "purchid", "type", - "ownershipsch", - "othtype", + "ownership", + "collectionyear", "jointmore", - "jointpur", + "joint", "beds", - "companybuy", "ethnic", - "ethnic_group", - "buy1livein", - "buylivein", + "ethnicgroup1", + "liveinbuyer1", "builtype", "proptype", "noint", - "buy2livein", + "liveinbuyer2", "privacynotice", "wheel", "hholdcount", "la", - "la_known", "income1", - "income1nk", - "details_known_2", - "details_known_3", - "details_known_4", + "inc1nk", "inc1mort", "income2", - "income2nk", + "inc2nk", "savingsnk", "savings", "prevown", - "updated_by_id", - "income1_value_check", + "amendedby", + "amendedbyid", "mortgage", "inc2mort", - "mortgage_value_check", "hb", - "savings_value_check", - "deposit_value_check", "frombeds", "staircase", "stairbought", "stairowned", "mrent", - "exdate", - "exday", - "exmonth", - "exyear", "resale", "deposit", "cashdis", "disabled", - "lanomagr", - "wheel_value_check", - "soctenant", "value", "equity", "discount", "grant", - "pregyrha", - "pregla", - "pregghb", - "pregother", - "ppostcode_full", - "is_previous_la_inferred", "ppcodenk", "ppostc1", "ppostc2", "prevloc", - "previous_la_known", + "prevlocname", + "previouslaknown", "hhregres", "hhregresstill", "proplen", - "has_mscharge", + "hasmscharge", "mscharge", "prevten", "mortgageused", "wchair", - "income2_value_check", "armedforcesspouse", - "hodate", "hoday", "homonth", "hoyear", "fromprop", "socprevten", - "mortgagelender", - "mortgagelenderother", - "mortlen", + "mortlen1", "extrabor", - "hhmemb", - "totadult", - "totchild", "hhtype", - "pcode1", - "pcode2", - "pcodenk", - "postcode_full", - "is_la_inferred", - "bulk_upload_id", - "retirement_value_check", - "hodate_check", - "extrabor_value_check", - "deposit_and_mortgage_value_check", - "shared_ownership_deposit_value_check", - "grant_value_check", + "postcode", + "islainferred", + "bulkuploadid", "value_value_check", - "old_persons_shared_ownership_value_check", - "staircase_bought_value_check", - "monthly_charges_value_check", - "details_known_5", - "details_known_6", - "saledate_check", "prevshared", "staircasesale", - "ethnic_group2", - "ethnicbuy2", - "proplen_asked", - "old_id", + "ethnicgroup2", + "ethnic2", "buy2living", - "prevtenbuy2", - "pregblank", + "prevten2", "uprn", - "uprn_known", - "uprn_confirmed", - "address_line1", - "address_line2", - "town_or_city", + "address1", + "address2", + "towncity", "county", - "nationalbuy2", - "discounted_sale_value_check", - "student_not_child_value_check", - "percentage_discount_value_check", - "combined_income_value_check", - "buyer_livein_value_check", - "discarded_at", - "stairowned_value_check", - "creation_method", - "old_form_id", - "managing_organisation_id", - "duplicate_set_id", - "nationality_all", - "nationality_all_group", - "nationality_all_buyer2", - "nationality_all_buyer2_group", - "address_line1_input", - "postcode_full_input", + "laname", + "creationmethod", + "nationalityall1", + "nationalityall2", + "mscharge_value_check", + "address1input", + "postcodeinput", "address_search_value_check", - "uprn_selection", - "address_line1_as_entered", - "address_line2_as_entered", - "town_or_city_as_entered", - "county_as_entered", - "postcode_full_as_entered", - "la_as_entered", - "partner_under_16_value_check", - "multiple_partners_value_check", - "created_by_id", - "has_management_fee", - "management_fee", + "uprnselected", + "bulkaddress1", + "bulkaddress2", + "bulktowncity", + "bulkcounty", + "bulkpostcode", + "bulkla", + "createdby", + "createdbyid", + "has_estate_fee", + "estate_fee", "firststair", "numstair", - "mrentprestaircasing", - "lasttransaction", - "initialpurchase"] + "stairlastday", + "stairlastmonth", + "stairlastyear", + "stairinitialyear", + "stairinitialmonth", + "stairinitialday"] (1..6).each do |index| EXPORT_FIELDS << "age#{index}" - EXPORT_FIELDS << "age#{index}_known" EXPORT_FIELDS << "ecstat#{index}" EXPORT_FIELDS << "sex#{index}" end diff --git a/app/services/exports/sales_log_export_service.rb b/app/services/exports/sales_log_export_service.rb index bfdc6177e..49508e379 100644 --- a/app/services/exports/sales_log_export_service.rb +++ b/app/services/exports/sales_log_export_service.rb @@ -41,7 +41,80 @@ module Exports end def apply_cds_transformation(sales_log, _export_mode) - sales_log.attributes_before_type_cast + attribute_hash = sales_log.attributes_before_type_cast + + attribute_hash["day"] = sales_log.saledate&.day + attribute_hash["month"] = sales_log.saledate&.month + attribute_hash["year"] = sales_log.saledate&.year + + attribute_hash["createddate"] = sales_log.created_at&.iso8601 + attribute_hash["createdby"] = sales_log.created_by&.email + attribute_hash["createdbyid"] = sales_log.created_by_id + attribute_hash["username"] = sales_log.assigned_to&.email + attribute_hash["usernameid"] = sales_log.assigned_to_id + attribute_hash["uploaddate"] = sales_log.updated_at&.iso8601 + attribute_hash["amendedby"] = sales_log.updated_by&.email + attribute_hash["amendedbyid"] = sales_log.updated_by_id + + attribute_hash["owningorgid"] = sales_log.owning_organisation&.id + attribute_hash["owningorgname"] = sales_log.owning_organisation&.name + attribute_hash["maningorgid"] = sales_log.managing_organisation&.id + attribute_hash["maningorgname"] = sales_log.managing_organisation&.name + + attribute_hash["creationmethod"] = sales_log.creation_method_before_type_cast + attribute_hash["bulkuploadid"] = sales_log.bulk_upload_id + attribute_hash["collectionyear"] = sales_log.form.start_date.year + attribute_hash["ownership"] = sales_log.ownershipsch + attribute_hash["joint"] = sales_log.jointpur + attribute_hash["ethnicgroup1"] = sales_log.ethnic_group + attribute_hash["ethnicgroup2"] = sales_log.ethnic_group2 + attribute_hash["previouslaknown"] = sales_log.previous_la_known + attribute_hash["hasmscharge"] = sales_log.has_mscharge + + attribute_hash["hoday"] = sales_log.hodate&.day + attribute_hash["homonth"] = sales_log.hodate&.month + attribute_hash["hoyear"] = sales_log.hodate&.year + + attribute_hash["inc1nk"] = sales_log.income1nk + attribute_hash["inc2nk"] = sales_log.income2nk + attribute_hash["postcode"] = sales_log.postcode_full + attribute_hash["islainferred"] = sales_log.is_la_inferred + attribute_hash["mortlen1"] = sales_log.mortlen + attribute_hash["ethnic2"] = sales_log.ethnicbuy2 + attribute_hash["prevten2"] = sales_log.prevtenbuy2 + + attribute_hash["address1"] = sales_log.address_line1 + attribute_hash["address2"] = sales_log.address_line2 + attribute_hash["towncity"] = sales_log.town_or_city + attribute_hash["laname"] = LocalAuthority.find_by(code: sales_log.la)&.name + attribute_hash["address1input"] = sales_log.address_line1_input + attribute_hash["postcodeinput"] = sales_log.postcode_full_input + attribute_hash["uprnselected"] = sales_log.uprn_selection + + attribute_hash["bulkaddress1"] = sales_log.address_line1_as_entered + attribute_hash["bulkaddress2"] = sales_log.address_line2_as_entered + attribute_hash["bulktowncity"] = sales_log.town_or_city_as_entered + attribute_hash["bulkcounty"] = sales_log.county_as_entered + attribute_hash["bulkpostcode"] = sales_log.postcode_full_as_entered + attribute_hash["bulkla"] = sales_log.la_as_entered + attribute_hash["nationalityall1"] = sales_log.nationality_all + attribute_hash["nationalityall2"] = sales_log.nationality_all_buyer2 + attribute_hash["prevlocname"] = LocalAuthority.find_by(code: sales_log.prevloc)&.name + attribute_hash["liveinbuyer1"] = sales_log.buy1livein + attribute_hash["liveinbuyer2"] = sales_log.buy2livein + + attribute_hash["has_estate_fee"] = sales_log.has_management_fee + attribute_hash["estate_fee"] = sales_log.management_fee + + attribute_hash["stairlastday"] = sales_log.lasttransaction&.day + attribute_hash["stairlastmonth"] = sales_log.lasttransaction&.month + attribute_hash["stairlastyear"] = sales_log.lasttransaction&.year + + attribute_hash["stairinitialday"] = sales_log.initialpurchase&.day + attribute_hash["stairinitialmonth"] = sales_log.initialpurchase&.month + attribute_hash["stairinitialyear"] = sales_log.initialpurchase&.year + attribute_hash["mscharge_value_check"] = sales_log.monthly_charges_value_check + attribute_hash end def is_omitted_field?(field_name, _sales_log) diff --git a/spec/fixtures/exports/sales_log.xml b/spec/fixtures/exports/sales_log.xml index 02ec1adc5..fb59de54e 100644 --- a/spec/fixtures/exports/sales_log.xml +++ b/spec/fixtures/exports/sales_log.xml @@ -3,66 +3,38 @@
diff --git a/spec/fixtures/exports/sales_log_2024.xml b/spec/fixtures/exports/sales_log_2024.xml index 3b4ce2221..caf57e7cf 100644 --- a/spec/fixtures/exports/sales_log_2024.xml +++ b/spec/fixtures/exports/sales_log_2024.xml @@ -3,66 +3,38 @@ diff --git a/spec/services/exports/sales_log_export_service_spec.rb b/spec/services/exports/sales_log_export_service_spec.rb index 801b9076b..14571d88a 100644 --- a/spec/services/exports/sales_log_export_service_spec.rb +++ b/spec/services/exports/sales_log_export_service_spec.rb @@ -17,9 +17,13 @@ RSpec.describe Exports::SalesLogExportService do def replace_entity_ids(sales_log, export_template) export_template.sub!(/\{owning_org_id\}/, sales_log["owning_organisation_id"].to_s) + export_template.sub!(/\{owning_org_name\}/, sales_log.owning_organisation.name.to_s) export_template.sub!(/\{managing_org_id\}/, sales_log["managing_organisation_id"].to_s) + export_template.sub!(/\{managing_org_name\}/, sales_log.managing_organisation.name.to_s) export_template.sub!(/\{assigned_to_id\}/, sales_log["assigned_to_id"].to_s) + export_template.sub!(/\{assigned_to_email\}/, sales_log.assigned_to&.email.to_s) export_template.sub!(/\{created_by_id\}/, sales_log["created_by_id"].to_s) + export_template.sub!(/\{created_by_email\}/, sales_log.created_by&.email.to_s) export_template.sub!(/\{id\}/, sales_log["id"].to_s) end