diff --git a/app/models/validations/sales/setup_validations.rb b/app/models/validations/sales/setup_validations.rb index e32fa70a1..a28777a17 100644 --- a/app/models/validations/sales/setup_validations.rb +++ b/app/models/validations/sales/setup_validations.rb @@ -20,7 +20,7 @@ module Validations::Sales::SetupValidations return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use? if record.saledate > Time.zone.today + 14.days - record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after") + record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.not_within.next_two_weeks") end end @@ -28,16 +28,16 @@ module Validations::Sales::SetupValidations return unless record.saledate && date_valid?("saledate", record) if merged_owning_organisation_inactive?(record) - record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_merged_organisations_saledate", + record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.invalid.merged_organisations", owning_organisation: record.owning_organisation.name, - owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), - owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name) + merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), + absorbing_organisation: record.owning_organisation.absorbing_organisation.name) end if absorbing_owning_organisation_inactive?(record) - record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_absorbing_organisations_saledate", + record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.invalid.absorbing_organisations", owning_organisation: record.owning_organisation.name, - owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) + available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) end end @@ -46,14 +46,14 @@ module Validations::Sales::SetupValidations if record.owning_organisation.present? if record.owning_organisation&.merge_date.present? && record.owning_organisation.merge_date <= record.saledate - record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_merged_organisation_sales", + record.errors.add :owning_organisation_id, I18n.t("validations.sales.setup.owning_organisation.inactive.merged_organisation", owning_organisation: record.owning_organisation.name, - owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), - owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name) + merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date), + absorbing_organisation: record.owning_organisation.absorbing_organisation.name) elsif record.owning_organisation&.absorbed_organisations.present? && record.owning_organisation.available_from.present? && record.owning_organisation.available_from.to_date > record.saledate.to_date - record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_absorbing_organisation_sales", + record.errors.add :owning_organisation_id, I18n.t("validations.sales.setup.owning_organisation.inactive.absorbing_organisation", owning_organisation: record.owning_organisation.name, - owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) + available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date)) end end end @@ -77,24 +77,22 @@ private end def saledate_validation_error_message - current_end_year_long = current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y") - if FormHandler.instance.sales_in_crossover_period? I18n.t( - "validations.setup.saledate.previous_and_current_collection_year", + "validations.sales.setup.saledate.must_be_within.previous_and_current_collection_year", previous_start_year_short: previous_collection_start_date.strftime("%y"), previous_end_year_short: previous_collection_end_date.strftime("%y"), previous_start_year_long: previous_collection_start_date.strftime("#{previous_collection_start_date.day.ordinalize} %B %Y"), current_end_year_short: current_collection_end_date.strftime("%y"), - current_end_year_long:, + current_end_year_long: current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y"), ) else I18n.t( - "validations.setup.saledate.current_collection_year", + "validations.sales.setup.saledate.must_be_within.current_collection_year", current_start_year_short: current_collection_start_date.strftime("%y"), - current_end_year_short: current_collection_end_date.strftime("%y"), current_start_year_long: current_collection_start_date.strftime("#{current_collection_start_date.day.ordinalize} %B %Y"), - current_end_year_long:, + current_end_year_short: current_collection_end_date.strftime("%y"), + current_end_year_long: current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y"), ) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7aef84fea..85be0e677 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -281,14 +281,7 @@ en: intermediate_rent_product_name: blank: "Enter name of other intermediate rent product." saledate: - later_than_14_days_after: "Sale completion date must not be later than 14 days from today’s date." - current_collection_year: - "Enter a date within the %{current_start_year_short}/%{current_end_year_short} collection year, which is between %{current_start_year_long} and %{current_end_year_long}." - previous_and_current_collection_year: - "Enter a date within the %{previous_start_year_short}/%{previous_end_year_short} or %{previous_end_year_short}/%{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}." year_not_two_digits: "Sale completion year must be 2 digits." - invalid_merged_organisations_saledate: "Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}." - invalid_absorbing_organisations_saledate: "Enter a date when the owning organisation was active. %{owning_organisation} became active on %{owning_organisation_available_from}." type: percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type." @@ -341,8 +334,6 @@ en: data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation." inactive_merged_organisation: "The owning organisation must be active on the tenancy start date. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}." inactive_absorbing_organisation: "The owning organisation must be active on the tenancy start date. %{owning_organisation} became active on %{owning_organisation_available_from}." - inactive_merged_organisation_sales: "The owning organisation must be active on the sale completion date. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}." - inactive_absorbing_organisation_sales: "The owning organisation must be active on the sale completion date. %{owning_organisation} became active on %{owning_organisation_available_from}." managing_organisation: invalid: "Please select the owning organisation or managing organisation that you belong to." data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the managing organisation." diff --git a/config/locales/validations/sales/setup.en.yml b/config/locales/validations/sales/setup.en.yml new file mode 100644 index 000000000..2741464b0 --- /dev/null +++ b/config/locales/validations/sales/setup.en.yml @@ -0,0 +1,25 @@ +en: + validations: + sales: + setup: + saledate: + not_within: + next_two_weeks: "Sale completion date must not be later than 14 days from today’s date." + must_be_within: + current_collection_year: + "Enter a date within the %{current_start_year_short}/%{current_end_year_short} collection year, which is between %{current_start_year_long} and %{current_end_year_long}." + previous_and_current_collection_year: + "Enter a date within the %{previous_start_year_short}/%{previous_end_year_short} or %{previous_end_year_short}/%{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}." + invalid: + merged_organisations: + "Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{merge_date} and was replaced by %{absorbing_organisation}." + absorbing_organisations: + "Enter a date when the owning organisation was active. %{owning_organisation} became active on %{available_from}." + + owning_organisation: + inactive: + merged_organisation: + "The owning organisation must be active on the sale completion date. %{owning_organisation} became inactive on %{merge_date} and was replaced by %{absorbing_organisation}." + absorbing_organisation: + "The owning organisation must be active on the sale completion date. %{owning_organisation} became active on %{available_from}." +