Browse Source

feat: wip blank fields and dependent fields on upload tos ee if valid and can upload with missing info - this is not the exact ac on the ticket yet

pull/1538/head
natdeanlewissoftwire 2 years ago
parent
commit
136e5f6f12
  1. 3
      app/models/log.rb
  2. 20
      app/services/bulk_upload/lettings/validator.rb
  3. 2
      app/services/bulk_upload/processor.rb
  4. 10
      db/seeds.rb

3
app/models/log.rb

@ -102,6 +102,9 @@ class Log < ApplicationRecord
next if setup_ids.include?(error.attribute.to_s)
public_send("#{error.attribute}=", nil)
form.conditional_question_conditions.map { |c| c[:from] if c[:to] == error.attribute }.compact.each do |conditional_attribute|
public_send("#{conditional_attribute}=", nil)
end
end
end

20
app/services/bulk_upload/lettings/validator.rb

@ -40,12 +40,30 @@ class BulkUpload::Lettings::Validator
end
end
def create_logs?
def can_create_logs?
return false if any_setup_errors?
return false if row_parsers.any?(&:block_log_creation?)
if row_parsers.all? { |row_parser| row_parser.log.valid? }
true
else
row_parsers.each do |row_parser|
next if row_parser.log.valid?
row_parser.log.errors.each do |error|
attribute = error.attribute.to_s
if row_parser.log.form.questions.find { |q| q.id == attribute }.type != "radio"
row_parser.log[attribute] = nil
row_parser.log.form.conditional_question_conditions.map { |c| c[:from] if c[:to] == attribute}.compact.each do |conditional_attribute|
row_parser.log[conditional_attribute] = nil
end
end
end
end
row_parsers.all? { |row_parser| row_parser.log.valid? }
end
end
def self.question_for_field(field)
QUESTIONS[field]

2
app/services/bulk_upload/processor.rb

@ -14,7 +14,7 @@ class BulkUpload::Processor
if validator.any_setup_errors?
send_setup_errors_mail
elsif validator.create_logs?
elsif validator.can_create_logs?
create_logs
if created_logs_but_incompleted?

10
db/seeds.rb

@ -98,6 +98,16 @@ unless Rails.env.test?
user.confirmed_at = Time.zone.now
end
User.find_or_create_by!(
name: "Nat",
email: "nat.dean-lewis@softwire.com",
organisation: org,
role: "data_coordinator",
) do |user|
user.password = "password"
user.confirmed_at = Time.zone.now
end
standalone_no_stock = Organisation.find_or_create_by!(
name: "Standalone No Stock 1 Ltd",
address_line1: "2 Marsham Street",

Loading…
Cancel
Save