Browse Source

Consolidate tenancy validation functionality into scheme validation

pull/2510/head
Manny Dinssa 2 years ago
parent
commit
20e0715db9
  1. 2
      app/models/scheme.rb
  2. 11
      app/models/validations/shared_validations.rb
  3. 1
      config/locales/en.yml

2
app/models/scheme.rb

@ -299,7 +299,7 @@ class Scheme < ApplicationRecord
active? && locations.active.exists?
end
def any_location_active_on_date?(date)
def has_active_locations_on_date?(date)
return false unless date
locations.any? { |location| date && location.active_on_date?(date) }

11
app/models/validations/shared_validations.rb

@ -82,16 +82,9 @@ module Validations::SharedValidations
record.errors.add :startdate, I18n.t("validations.setup.startdate.scheme.#{scope}.startdate", name: record.scheme.service_name, date:, deactivation_date:)
record.errors.add :scheme_id, I18n.t("validations.setup.startdate.scheme.#{scope}.scheme_id", name: record.scheme.service_name, date:, deactivation_date:)
end
end
def tenancy_during_startdate_validation(record)
return if record.startdate.blank?
if record.scheme.present? && !record.scheme.any_location_active_on_date?(record.startdate)
if record.scheme.present? && !record.scheme.has_active_locations_on_date?(record.startdate)
record.errors.add :startdate, I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: record.scheme.service_name)
end
if record.location.present? && !record.location.active_on_date?(record.startdate)
record.errors.add :startdate, I18n.t("validations.setup.startdate.location.deactivated.startdate", postcode: record.location.postcode)
record.errors.add :scheme_id, I18n.t("validations.setup.startdate.scheme.locations_inactive.scheme_id", name: record.scheme.service_name)
end
end

1
config/locales/en.yml

@ -302,6 +302,7 @@ en:
scheme_id: "The scheme %{name} is not available until %{date}. Select another scheme or edit the tenancy start date"
locations_inactive:
startdate: "The scheme %{name} has no locations that are active on this date. Enter another date or choose another scheme."
scheme_id: "The scheme %{name} has no locations that are active on this date. Enter another date or choose another scheme."
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."

Loading…
Cancel
Save