2 changed files with 12 additions and 5 deletions
@ -1,17 +1,17 @@ |
|||||||
class OrganisationRelationship < ApplicationRecord |
class OrganisationRelationship < ApplicationRecord |
||||||
belongs_to :child_organisation, class_name: "Organisation" |
belongs_to :child_organisation, class_name: "Organisation" |
||||||
belongs_to :parent_organisation, class_name: "Organisation" |
belongs_to :parent_organisation, class_name: "Organisation" |
||||||
validates :parent_organisation_id, presence: { message: "You must choose a housing provider" } |
validates :parent_organisation_id, presence: { message: I18n.t("validations.organisation.housing_provider.blank") } |
||||||
validates :child_organisation_id, presence: { message: "You must choose a managing agent" } |
validates :child_organisation_id, presence: { message: I18n.t("validations.organisation.managing_agent.blank") } |
||||||
validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: "You have already added this housing provider" } |
validates :parent_organisation_id, uniqueness: { scope: :child_organisation_id, message: I18n.t("validations.organisation.housing_provider.already_added") } |
||||||
validates :child_organisation_id, uniqueness: { scope: :parent_organisation_id, message: "You have already added this managing agent" } |
validates :child_organisation_id, uniqueness: { scope: :parent_organisation_id, message: I18n.t("validations.organisation.managing_agent.already_added") } |
||||||
validate :validate_housing_provider_owns_stock, on: :housing_provider |
validate :validate_housing_provider_owns_stock, on: :housing_provider |
||||||
|
|
||||||
private |
private |
||||||
|
|
||||||
def validate_housing_provider_owns_stock |
def validate_housing_provider_owns_stock |
||||||
if parent_organisation_id.present? && !parent_organisation.holds_own_stock |
if parent_organisation_id.present? && !parent_organisation.holds_own_stock |
||||||
errors.add :parent_organisation_id, I18n.t("validations.scheme.owning_organisation.does_not_own_stock") |
errors.add :parent_organisation_id, I18n.t("validations.organisation.housing_provider.does_not_own_stock") |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
|
|||||||
Loading…
Reference in new issue