From 77e030f9d4a3ca2f8173699ed95ea9e97ad78427 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 30 Apr 2025 17:14:16 +0100 Subject: [PATCH] only annotate errors to the other fields if there was an error --- app/services/bulk_upload/lettings/year2024/row_parser.rb | 7 +++++-- app/services/bulk_upload/lettings/year2025/row_parser.rb | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index 101352f0a..064aa3f26 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -945,8 +945,11 @@ private errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.missing_charges", sentence_fragment: charge)) end - other_charge_fields.each_key do |field| - errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.related_to_missing_charge")) + # if there were any errors, add an error to all the remaining present charges to make this entire section invalid + if blank_charge_fields.any? + other_charge_fields.each_key do |field| + errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.related_to_missing_charge")) + end end end diff --git a/app/services/bulk_upload/lettings/year2025/row_parser.rb b/app/services/bulk_upload/lettings/year2025/row_parser.rb index 61351764b..0745056d2 100644 --- a/app/services/bulk_upload/lettings/year2025/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2025/row_parser.rb @@ -944,8 +944,11 @@ private errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.missing_charges", sentence_fragment: charge)) end - other_charge_fields.each_key do |field| - errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.related_to_missing_charge")) + # if there were any errors, add an error to all the remaining present charges to make this entire section invalid + if blank_charge_fields.any? + other_charge_fields.each_key do |field| + errors.add(field, I18n.t("#{ERROR_BASE_KEY}.charges.related_to_missing_charge")) + end end end