From 191f727e4fd31dc79e50d217162e0d4023f34b08 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Wed, 30 Nov 2022 10:52:05 +0000 Subject: [PATCH] feat: start adding scheme validation for when owning org doesn't hold stock --- app/models/scheme.rb | 9 ++++++++- config/locales/en.yml | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 67b577ed2..9150d4cba 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -21,7 +21,7 @@ class Scheme < ApplicationRecord scope :order_by_completion, -> { order("confirmed ASC NULLS FIRST") } scope :order_by_service_name, -> { order(service_name: :asc) } - validate :validate_confirmed + validate :validate_confirmed, :validate_owning_organisation auto_strip_attributes :service_name @@ -212,6 +212,13 @@ class Scheme < ApplicationRecord end end + def validate_owning_organisation + if !owning_organisation.holds_own_stock? + errors.add(:owning_organisation_id, :does_not_own_stock, message: I18n.t("validations.scheme.owning_organisation.does_not_own_stock")) + owning_organisation = nil + end + end + def available_from FormHandler.instance.collection_start_date(created_at) end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2463041f9..6c2d7db46 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -341,6 +341,8 @@ en: before_deactivation: "This scheme was deactivated on %{date}. The reactivation date must be on or after deactivation date" deactivation: during_deactivated_period: "The scheme is already deactivated during this date, please enter a different date" + owning_organisation: + does_not_own_stock: "Enter an organisation that owns housing stock"