Browse Source

refactor: use log to infer field values when checking for duplicates

cldc-1888-bulk-upload-duplicate-log-validation
Sam Seed 2 years ago
parent
commit
d9fabb03f6
  1. 54
      app/services/bulk_upload/lettings/row_parser.rb

54
app/services/bulk_upload/lettings/row_parser.rb

@ -315,21 +315,21 @@ private
end
def log_already_exists?
field_mappings = {
"startdate" => startdate,
"postcode_full" => postcode_full,
"brent" => brent,
"scharge" => scharge,
"pscharge" => pscharge,
"supcharg" => supcharg,
"tenancycode" => field_7,
"age1" => field_12,
"sex1" => field_20,
"ecstat1" => field_35,
"ethnic" => field_43,
}
LettingsLog.exists?(field_mappings)
fields_for_duplicity_check = %w(
startdate
postcode_full
brent
scharge
pscharge
supcharg
tenancycode
age1
sex1
ecstat1
ethnic
)
LettingsLog.exists?(Hash[fields_for_duplicity_check.collect { |field| [field, log[field]] }])
end
def field_mapping_for_errors
@ -922,30 +922,6 @@ private
end
end
def brent
if %i[field_80 field_81 field_82 field_83].any? { |f| public_send(f).present? }
self.field_80 ||= 0
end
end
def scharge
if %i[field_80 field_81 field_82 field_83].any? { |f| public_send(f).present? }
self.field_81 ||= 0
end
end
def pscharge
if %i[field_80 field_81 field_82 field_83].any? { |f| public_send(f).present? }
self.field_82 ||= 0
end
end
def supcharg
if %i[field_80 field_81 field_82 field_83].any? { |f| public_send(f).present? }
self.field_83 ||= 0
end
end
def scheme
@scheme ||= Scheme.find_by(old_visible_id: field_4)
end

Loading…
Cancel
Save