diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 8eda72c49..7955cbe6e 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -56,7 +56,7 @@ module Imports attributes["builtype"] = unsafe_string_as_integer(xml_doc, "Q13BuildingType") attributes["proptype"] = unsafe_string_as_integer(xml_doc, "Q12PropertyType") attributes["privacynotice"] = 1 if string_or_nil(xml_doc, "Qdp") == "Yes" - attributes["noint"] = safe_string_as_integer(xml_doc, "NOINT") || 2 if attributes["privacynotice"] == 1 + attributes["noint"] = unsafe_string_as_integer(xml_doc, "PartAPurchaser") attributes["buy2livein"] = unsafe_string_as_integer(xml_doc, "LiveInBuyer2") attributes["wheel"] = unsafe_string_as_integer(xml_doc, "Q10Wheelchair") attributes["hholdcount"] = safe_string_as_integer(xml_doc, "LiveInOther") || 0 @@ -82,11 +82,11 @@ module Imports attributes["exmonth"] = safe_string_as_integer(xml_doc, "EXMONTH") attributes["exyear"] = safe_string_as_integer(xml_doc, "EXYEAR") attributes["resale"] = unsafe_string_as_integer(xml_doc, "Q17Resale") - attributes["deposit"] = safe_string_as_decimal(xml_doc, "Q26CashDeposit") + attributes["deposit"] = deposit(xml_doc, attributes) attributes["cashdis"] = safe_string_as_decimal(xml_doc, "Q27SocialHomeBuy") attributes["disabled"] = unsafe_string_as_integer(xml_doc, "Disability") attributes["lanomagr"] = unsafe_string_as_integer(xml_doc, "Q19Rehoused") - attributes["value"] = safe_string_as_decimal(xml_doc, "Q22PurchasePrice") + attributes["value"] = purchase_price(xml_doc, attributes) attributes["equity"] = safe_string_as_decimal(xml_doc, "Q23Equity") attributes["discount"] = safe_string_as_decimal(xml_doc, "Q33Discount") attributes["grant"] = safe_string_as_decimal(xml_doc, "Q32Reductions") @@ -103,7 +103,7 @@ module Imports attributes["hhregres"] = unsafe_string_as_integer(xml_doc, "ArmedF") attributes["hhregresstill"] = still_serving(xml_doc) attributes["proplen"] = safe_string_as_integer(xml_doc, "Q16aProplen2") - attributes["mscharge"] = safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") + attributes["mscharge"] = monthly_charges(xml_doc, attributes) attributes["mscharge_known"] = 1 if attributes["mscharge"].present? attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q6PrevTenure") attributes["mortgageused"] = unsafe_string_as_integer(xml_doc, "MORTGAGEUSED") @@ -118,7 +118,7 @@ module Imports attributes["mortgagelender"] = mortgage_lender(xml_doc, attributes) attributes["mortgagelenderother"] = nil # Q24AMORTGAGELENDEROTHER Q34AMORTGAGELENDEROTHER Q41AMORTGAGELENDEROTHER attributes["mortlen"] = mortgage_length(xml_doc, attributes) - attributes["extrabor"] = unsafe_string_as_integer(xml_doc, "Q25Borrowing") + attributes["extrabor"] = borrowing(xml_doc, attributes) attributes["totadult"] = safe_string_as_integer(xml_doc, "TOTADULT") # would get overridden attributes["totchild"] = safe_string_as_integer(xml_doc, "TOTCHILD") # would get overridden attributes["hhtype"] = unsafe_string_as_integer(xml_doc, "HHTYPE") @@ -154,6 +154,7 @@ module Imports def save_sales_log(attributes, previous_status) sales_log = SalesLog.new(attributes) + binding.pry begin sales_log.save! sales_log @@ -233,14 +234,14 @@ module Imports end end - def mortgage_lender(xml_doc, attributes) + def mortgage_lender(xml_doc, attributes) #this comes through as a string, need to map to a corresponding integer case attributes["ownershipsch"] when 1 - unsafe_string_as_integer(xml_doc, "Q24aMortgageLender") + string_or_nil(xml_doc, "Q24aMortgageLender") when 2 - unsafe_string_as_integer(xml_doc, "Q34aMortgageLender") + string_or_nil(xml_doc, "Q34a") when 3 - unsafe_string_as_integer(xml_doc, "Q41aMortgageLender") + string_or_nil(xml_doc, "Q41aMortgageLender") end end @@ -292,5 +293,50 @@ module Imports 1 end end + + def borrowing(xml_doc, attributes) + case attributes["ownershipsch"] + when 1 + unsafe_string_as_integer(xml_doc, "Q25Borrowing") + when 2 + unsafe_string_as_integer(xml_doc, "Q35Borrowing") + when 3 + unsafe_string_as_integer(xml_doc, "Q42Borrowing") + end + end + + def purchase_price(xml_doc, attributes) + case attributes["ownershipsch"] + when 1 + safe_string_as_decimal(xml_doc, "Q22PurchasePrice") + when 2 + safe_string_as_decimal(xml_doc, "Q31PurchasePrice") + when 3 + safe_string_as_decimal(xml_doc, "Q40PurchasePrice") + end + end + + def deposit(xml_doc, attributes) + case attributes["ownershipsch"] + when 1 + safe_string_as_decimal(xml_doc, "Q26CashDeposit") + when 2 + safe_string_as_decimal(xml_doc, "Q36CashDeposit") + when 3 + safe_string_as_decimal(xml_doc, "Q43CashDeposit") + end + end + + def monthly_charges(xml_doc, attributes) + safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") + case attributes["ownershipsch"] + when 1 + safe_string_as_decimal(xml_doc, "Q29MonthlyCharges") + when 2 + safe_string_as_decimal(xml_doc, "Q37MonthlyCharges") + when 3 + #what should this be? + end + end end end diff --git a/spec/fixtures/imports/sales_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml b/spec/fixtures/imports/sales_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml index c48e01234..58aada97b 100644 --- a/spec/fixtures/imports/sales_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml +++ b/spec/fixtures/imports/sales_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2023-02-21T12:09:45.809134Z - 2023-02-21T12:09:45.809134Z + 2023-02-22T10:59:01.709949Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 0 0 -
300201
+
300202
@@ -198,35 +198,35 @@ - + 3 Private tenant B95 5HZ Stratford-on-Avon E07000221 - + Yes - + 7 No - - + 2 No + 2 No - + 2 No - + 4 Don’t know - + 2 No @@ -315,10 +315,10 @@ 0 0 0 - 0 + 1 0 0 - 0 + 1 diff --git a/spec/fixtures/imports/sales_logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml b/spec/fixtures/imports/sales_logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml index 602a4dd42..a3ab2d625 100644 --- a/spec/fixtures/imports/sales_logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml +++ b/spec/fixtures/imports/sales_logs/0b4a68df-30cc-474a-93c0-a56ce8fdad3b.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09z2c55d9cb90d7ba84927e64618 7c5bd5fb549c09z2c55d9cb90d7ba84927e64618 2023-02-21T11:54:51.786722Z - 2023-02-21T11:54:51.786722Z + 2023-02-22T10:59:45.88188Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 0 1 -
300200
+
300203
@@ -195,7 +195,7 @@ 9EX SW1A 1AA - + 1 @@ -275,8 +275,8 @@ - 1 - 1 + 0 + 0 0 diff --git a/spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml b/spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml index 46bb69b9a..fe08c2412 100644 --- a/spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml +++ b/spec/fixtures/imports/sales_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2023-02-21T11:48:28.255968Z - 2023-02-21T11:49:27.630543Z + 2023-02-22T11:00:06.575832Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 235000 0 -
300199
+
300204
@@ -226,7 +226,7 @@ 4 Don’t know 1 Yes 89000 - + 1 Yes diff --git a/spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml b/spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml index 83c3f9a4c..17d481fa6 100644 --- a/spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml +++ b/spec/fixtures/imports/sales_logs/166fc004-392e-47a8-acb8-1c018734882b.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2023-02-21T11:48:28.255968Z - 2023-02-21T11:49:27.630543Z + 2023-02-22T11:00:06.575832Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 235000 0 -
300199
+
300204
@@ -226,7 +226,7 @@ 4 Don’t know 1 Yes 89000 - + 1 Yes diff --git a/spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml b/spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml index 47249accc..0eead66a5 100644 --- a/spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml +++ b/spec/fixtures/imports/sales_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2023-02-21T11:48:28.255968Z - 2023-02-21T11:49:27.630543Z + 2023-02-22T11:00:06.575832Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 235000 0 -
300199
+
300204
@@ -226,7 +226,7 @@ 4 Don’t know 1 Yes 89000 - + 1 Yes diff --git a/spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml b/spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml index 61063c217..be53abaf4 100644 --- a/spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml +++ b/spec/fixtures/imports/sales_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml @@ -6,7 +6,7 @@ 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 2023-02-21T11:48:28.255968Z - 2023-02-21T11:49:27.630543Z + 2023-02-22T11:00:06.575832Z submitted-valid 2022 Manual Entry @@ -150,7 +150,7 @@ 0 235000 0 -
300199
+
300204
@@ -226,7 +226,7 @@ 4 Don’t know 1 Yes 89000 - + 1 Yes