Browse Source

feat: update tenancy/scheme/location validations

pull/1739/head
natdeanlewissoftwire 3 years ago
parent
commit
503bace0bf
  1. 2
      app/models/derived_variables/lettings_log_variables.rb
  2. 14
      app/models/validations/shared_validations.rb
  3. 9
      config/locales/en.yml

2
app/models/derived_variables/lettings_log_variables.rb

@ -258,7 +258,7 @@ private
def reset_scheme_location! def reset_scheme_location!
self.location = nil 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 self.location = scheme.locations.first
end end
end end

14
app/models/validations/shared_validations.rb

@ -69,7 +69,8 @@ module Validations::SharedValidations
if location_inactive_status.present? if location_inactive_status.present?
date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date) 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
end end
@ -77,7 +78,8 @@ module Validations::SharedValidations
scheme_inactive_status = inactive_status(record.startdate, record.scheme) scheme_inactive_status = inactive_status(record.startdate, record.scheme)
if scheme_inactive_status.present? if scheme_inactive_status.present?
date, scope, deactivation_date = scheme_inactive_status.values_at(:date, :scope, :deactivation_date) 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
end end
@ -127,6 +129,14 @@ module Validations::SharedValidations
private 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) def person_is_partner?(relationship)
relationship == "P" relationship == "P"
end end

9
config/locales/en.yml

@ -250,11 +250,16 @@ en:
location: location:
deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered." 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" 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: scheme:
deactivated: "%{name} was deactivated on %{date} and was not available on the day you entered" 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" 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: owning_organisation:
invalid: "Please select the owning organisation or managing organisation that you belong to" 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." data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."

Loading…
Cancel
Save