From 1ead78462bebfc7105dcf4d8f3759b2d9ecc43cd Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 5 May 2022 17:19:49 +0100
Subject: [PATCH] Set tshortfall to 0 if it should exists but is not provided
(#550)
* Set tshortfall to 0 if it should exists but is not provided
* check if tshortfall is overridden
---
app/services/imports/case_logs_import_service.rb | 9 ++++++++-
app/services/imports/import_service.rb | 4 ++++
.../case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml | 2 +-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb
index ddb1b277d..066c55798 100644
--- a/app/services/imports/case_logs_import_service.rb
+++ b/app/services/imports/case_logs_import_service.rb
@@ -125,7 +125,7 @@ module Imports
attributes["tcharge"] = safe_string_as_decimal(xml_doc, "Q18av")
attributes["hbrentshortfall"] = unsafe_string_as_integer(xml_doc, "Q18d")
- attributes["tshortfall"] = safe_string_as_decimal(xml_doc, "Q18dyes")
+ attributes["tshortfall"] = tshortfall(xml_doc, attributes)
attributes["voiddate"] = compose_date(xml_doc, "VDAY", "VMONTH", "VYEAR")
attributes["mrcdate"] = compose_date(xml_doc, "MRCDAY", "MRCMONTH", "MRCYEAR")
@@ -513,5 +513,12 @@ module Imports
def people_with_details(xml_doc)
((2..8).map { |x| string_or_nil(xml_doc, "P#{x}Rel") } + [string_or_nil(xml_doc, "P1Sex")]).compact
end
+
+ def tshortfall(xml_doc, attributes)
+ shortfall = safe_string_as_decimal(xml_doc, "Q18dyes")
+ return 0 if shortfall.blank? && attributes["hbrentshortfall"] == 1 && overridden?(xml_doc, "xmlns", "Q18dyes")
+
+ shortfall
+ end
end
end
diff --git a/app/services/imports/import_service.rb b/app/services/imports/import_service.rb
index 3f319b358..664790055 100644
--- a/app/services/imports/import_service.rb
+++ b/app/services/imports/import_service.rb
@@ -22,6 +22,10 @@ module Imports
xml_document.at_xpath("//#{namespace}:#{field}")&.text
end
+ def overridden?(xml_document, namespace, field)
+ xml_document.at_xpath("//#{namespace}:#{field}").attributes["override-field"].value
+ end
+
def to_boolean(input_string)
input_string == "true"
end
diff --git a/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
index 30f1a2289..8fc8cf37d 100644
--- a/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
+++ b/spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
@@ -166,7 +166,7 @@
438.11
1 Yes
- 7.00
+
2021-09-30
0