diff --git a/app/models/scheme.rb b/app/models/scheme.rb index ca3624e3a..d4a35e776 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -235,7 +235,7 @@ class Scheme < ApplicationRecord end def status_at(date) - return :incomplete unless confirmed + return :incomplete unless confirmed && has_active_locations? return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date @@ -254,4 +254,8 @@ class Scheme < ApplicationRecord def deactivated? status == :deactivated end + + def has_active_locations? + locations.count { |location| %i[active deactivating_soon].include?(location.status) }.positive? + end end diff --git a/db/schema.rb b/db/schema.rb index 2cffbaf9f..9b40f55be 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -568,8 +568,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_20_084057) do t.string "town_or_city" t.string "county" t.integer "nationalbuy2" - t.integer "student_not_child_value_check" t.integer "discounted_sale_value_check" + t.integer "student_not_child_value_check" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true