diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index d4a549b86..d29f21ce2 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -258,7 +258,7 @@ private def reset_scheme_location! self.location = nil - if scheme && scheme.locations.active.size == 1 + if scheme && scheme.locations.active_in_2_weeks.size == 1 self.location = scheme.locations.first end end diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index 3b361e9d6..dfe6d14f2 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -69,7 +69,8 @@ module Validations::SharedValidations if location_inactive_status.present? date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date) - record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}", postcode: record.location.postcode, date:, deactivation_date:) + page = scheme_location_validation_page(field) + record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.#{page}", postcode: record.location.postcode, date:, deactivation_date:) end end @@ -77,7 +78,8 @@ module Validations::SharedValidations scheme_inactive_status = inactive_status(record.startdate, record.scheme) if scheme_inactive_status.present? date, scope, deactivation_date = scheme_inactive_status.values_at(:date, :scope, :deactivation_date) - record.errors.add field, I18n.t("validations.setup.startdate.scheme.#{scope}", name: record.scheme.service_name, date:, deactivation_date:) + page = scheme_location_validation_page(field) + record.errors.add field, I18n.t("validations.setup.startdate.scheme.#{scope}.#{page}", name: record.scheme.service_name, date:, deactivation_date:) end end @@ -127,6 +129,14 @@ module Validations::SharedValidations private + def scheme_location_validation_page(field) + case field + when :startdate then "date_page" + when :location_id then "location_page" + when :scheme_id then "scheme_page" + end + end + def person_is_partner?(relationship) relationship == "P" end diff --git a/config/locales/en.yml b/config/locales/en.yml index 49aa2d6f1..bdf17cbc3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -250,11 +250,16 @@ en: location: deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered." reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" - activating_soon: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" + activating_soon: + date_page: "The location %{postcode} is not available until %{date}. Enter a tenancy start date after %{date}" + location_page: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" + scheme_page: "This scheme's only location %{postcode} is not available until %{date}. Select another scheme or edit the tenancy start date" scheme: deactivated: "%{name} was deactivated on %{date} and was not available on the day you entered" reactivating_soon: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date" - activating_soon: "%{name} is not available until %{date}. Enter a tenancy start date after %{date}" + activating_soon: + date_page: "%{name} is not available until %{date}. Enter a tenancy start date after %{date}" + scheme_page: "%{name} is not available until %{date}. Select another scheme or edit the tenancy start date" owning_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 owning organisation."