diff --git a/app/models/local_authority.rb b/app/models/local_authority.rb index 21a17c6e4..86311e81f 100644 --- a/app/models/local_authority.rb +++ b/app/models/local_authority.rb @@ -9,7 +9,7 @@ def eligible_for_school_picker? end def organisations_for_multi_school_picker - organisations.local_authority_maintained.where.not(archived: true) + organisations.local_authority_maintained.active end def org_type diff --git a/app/models/support/category.rb b/app/models/support/category.rb index fde453f18..4e9bbd1d2 100644 --- a/app/models/support/category.rb +++ b/app/models/support/category.rb @@ -5,6 +5,8 @@ module Support # Types of procurement or "categories of spend" # class Category < ApplicationRecord + include Support::Concerns::ScopeActive + belongs_to :tower, class_name: "Support::Tower", foreign_key: "support_tower_id", optional: true has_many :cases, class_name: "Support::Case" belongs_to :parent, class_name: "Support::Category", optional: true @@ -24,7 +26,6 @@ class Category < ApplicationRecord scope :sub_categories, -> { where.not(parent_id: nil) } scope :ordered_by_title, -> { order(Arel.sql("case when support_categories.title = 'Or' then 1 else 0 end ASC, support_categories.title ASC")) } scope :except_for, ->(title) { where.not(title:) } - scope :active, -> { where(archived: false) } scope :with_live_cases, -> { joins(:cases).merge(Case.live) } delegate :title, to: :tower, prefix: true, allow_nil: true diff --git a/app/models/support/concerns/scope_active.rb b/app/models/support/concerns/scope_active.rb new file mode 100644 index 000000000..c17284b3b --- /dev/null +++ b/app/models/support/concerns/scope_active.rb @@ -0,0 +1,7 @@ +module Support::Concerns::ScopeActive + extend ActiveSupport::Concern + + included do + scope :active, -> { where(archived: false) } + end +end diff --git a/app/models/support/email_template.rb b/app/models/support/email_template.rb index 74e3edb4f..ca830123b 100644 --- a/app/models/support/email_template.rb +++ b/app/models/support/email_template.rb @@ -1,5 +1,7 @@ module Support class EmailTemplate < ApplicationRecord + include Support::Concerns::ScopeActive + STAGE_VALUES = [0, 1, 2, 3, 4].freeze belongs_to :group, class_name: "Support::EmailTemplateGroup", foreign_key: "template_group_id" @@ -12,7 +14,6 @@ class EmailTemplate < ApplicationRecord default_scope { order(:title) } - scope :active, -> { where(archived: false) } scope :by_groups, ->(template_group_ids) { where(template_group_id: template_group_ids) } scope :by_stages, ->(stages, include_null: false) { include_null ? where(stage: stages).or(where(stage: nil)) : where(stage: stages) } scope :without_stage, -> { where(stage: nil) } diff --git a/app/models/support/establishment_group.rb b/app/models/support/establishment_group.rb index f899f9e2d..cd5ecdcaa 100644 --- a/app/models/support/establishment_group.rb +++ b/app/models/support/establishment_group.rb @@ -32,6 +32,6 @@ def eligible_for_school_picker? end def organisations_for_multi_school_picker - organisations.where.not(archived: true) + organisations.active end end diff --git a/app/models/support/organisation.rb b/app/models/support/organisation.rb index 938bcf229..02cc93c9c 100644 --- a/app/models/support/organisation.rb +++ b/app/models/support/organisation.rb @@ -14,6 +14,7 @@ module Support # class Organisation < ApplicationRecord include Filterable + include Support::Concerns::ScopeActive belongs_to :establishment_type, counter_cache: true,