Browse Source

feat: add additional null checks to sales

pull/1687/head
natdeanlewissoftwire 3 years ago
parent
commit
e267671cb1
  1. 12
      app/services/bulk_upload/sales/year2022/row_parser.rb
  2. 12
      app/services/bulk_upload/sales/year2023/row_parser.rb

12
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -370,6 +370,7 @@ class BulkUpload::Sales::Year2022::RowParser
validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? }
validate :validate_data_protection_answered, on: :after_log
validate :validate_buyers_organisations, on: :after_log
def self.question_for_field(field)
QUESTIONS[field]
@ -461,6 +462,15 @@ private
end
end
def validate_buyers_organisations
organisations_fields = %i[field_44 field_45 field_46 field_47]
if organisations_fields.all? { |field| attributes[field.to_sym].blank? }
organisations_fields.each do |field|
errors.add(field, "At least one option must be selected of these four")
end
end
end
def buyer_not_interviewed?
field_6 == 1
end
@ -540,7 +550,6 @@ private
pregla: %i[field_45],
pregghb: %i[field_46],
pregother: %i[field_47],
pregblank: %i[field_44 field_45 field_46 field_47],
disabled: %i[field_48],
wheel: %i[field_49],
beds: %i[field_50],
@ -673,7 +682,6 @@ private
attributes["pregla"] = field_45
attributes["pregghb"] = field_46
attributes["pregother"] = field_47
attributes["pregblank"] = 1 if [field_44, field_45, field_46, field_47].all?(&:blank?)
attributes["disabled"] = buyer_not_interviewed? && field_48.blank? ? 3 : field_48
attributes["wheel"] = buyer_not_interviewed? && field_49.blank? ? 3 : field_49

12
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -467,6 +467,7 @@ class BulkUpload::Sales::Year2023::RowParser
validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? }
validate :validate_data_protection_answered, on: :after_log
validate :validate_buyers_organisations, on: :after_log
def self.question_for_field(field)
QUESTIONS[field]
@ -562,6 +563,15 @@ private
end
end
def validate_buyers_organisations
organisations_fields = %i[field_67 field_68 field_69 field_70]
if organisations_fields.all? { |field| attributes[field.to_sym].blank? }
organisations_fields.each do |field|
errors.add(field, "At least one option must be selected of these four")
end
end
end
def prevtenbuy2
case field_72
when "R"
@ -684,7 +694,6 @@ private
pregla: %i[field_69],
pregghb: %i[field_70],
pregother: %i[field_68],
pregblank: %i[field_67 field_69 field_70 field_68],
disabled: %i[field_76],
wheel: %i[field_77],
@ -847,7 +856,6 @@ private
attributes["pregla"] = field_69
attributes["pregghb"] = field_70
attributes["pregother"] = field_68
attributes["pregblank"] = 1 if [field_67, field_69, field_70, field_78].all?(&:blank?)
attributes["disabled"] = field_76
attributes["wheel"] = field_77

Loading…
Cancel
Save