Browse Source

Extract sales setup validations to translation file

pull/2677/head
Manny Dinssa 2 years ago
parent
commit
a5e4ceb7fc
  1. 38
      app/models/validations/sales/setup_validations.rb
  2. 21
      config/locales/validations/sales/setup/en.yml

38
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_saledate",
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_saledate",
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,25 +77,23 @@ 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

21
config/locales/validations/sales/setup/en.yml

@ -1,2 +1,23 @@
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_saledate:
"Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{merge_date} and was replaced by %{absorbing_organisation}."
absorbing_organisations_saledate:
"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}."
inactive_absorbing_organisation:
"The owning organisation must be active on the sale completion date. %{owning_organisation} became active on %{available_from}."

Loading…
Cancel
Save