Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

class Organisation < ApplicationRecord
has_many :users
has_many :owned_case_logs, class_name: "CaseLog", foreign_key: "owning_organisation_id"
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations
3 years ago
has_many :organisation_rent_periods
Cldc 1227 supported housing index (#648) * Added test file for supported housing schemes * Added factory bot for supported housing schemes * swapped managing agent to org for scheme * created migration for schemes * created model for scheme * added migration to add foreign key to the schemes table * missing spec and log spec for supported housing * fixed failing specs * added schemes migration * next step feature * added route * added controller * added index * added all schemes * correct test for scheme * added view * route alias for schemes * spec for index schemes * failing scheme controller spec * added simple view, scheme seed and authentication * spec for index schemes list * rubocop - thanks * better seed * added Heading to org * added feature flag to hide supported services on prod * added feature flag testing nav items * testing coordinator user can see the link to supported housing * moved toggle to a different place * moved toggle to PrimaryNavigationComponent * testing not being signed in on support pages * testing showing search bar * added search bar * testing subset of schemes for coordinator user * rubocop * failing test for title in page * code to expose title * pagination with tests without searching * partial for schemes * scoping out all but support and coord users * searching schemes code and test * searching via code and org tests * searching by org name tests * searching by org name code * search_by tests * search_by code * search_by woops must search by service * searching schemes feature * tests for data coordinator user * redirect for data coordinator user * testing org schemes for coordiantor user * schemes in org controller for coordiantor user * refactored specs moved into orgs what belongs there * view for org schemes * rubocop * accebility field * accebility field on org page * correct return when on org schemes * passing search test on the orgs page * highlight nav tab * navs helper done * rubocop * fixed failing tests for support user * correct view * how did I manage to delete this file? * checking you cant access schems unathorized * moved test * renamed service name * correct title for sup user schemes org * testing not being able to view any other orgs supported housing for coordinator user * Trigger WF * last fix * aded has many to org for schemes * rubocop Co-authored-by: Ted <ted.booton@madetech.com>
3 years ago
has_many :schemes
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) }
has_paper_trail
PROVIDER_TYPE = {
LA: 1,
PRP: 2,
}.freeze
enum provider_type: PROVIDER_TYPE
validates :name, presence: { message: I18n.t("validations.organisation.name_missing") }
validates :provider_type, presence: { message: I18n.t("validations.organisation.provider_type_missing") }
def case_logs
CaseLog.filter_by_organisation(self)
end
def completed_case_logs
case_logs.completed
end
def not_completed_case_logs
case_logs.not_completed
end
def address_string
%i[address_line1 address_line2 postcode].map { |field| public_send(field) }.join("\n")
end
def rent_periods
organisation_rent_periods.pluck(:rent_period)
end
def rent_period_labels
labels = rent_periods.map { |period| RentPeriod.rent_period_mappings[period.to_s]["value"] }
3 years ago
labels.presence || %w[All]
end
def data_protection_confirmed?
!!data_protection_confirmations.order(created_at: :desc).first&.confirmed
end
def data_protection_agreement_string
data_protection_confirmed? ? "Accepted" : "Not accepted"
end
DISPLAY_PROVIDER_TYPE = { "LA": "Local authority", "PRP": "Private registered provider" }.freeze
def display_provider_type
DISPLAY_PROVIDER_TYPE[provider_type.to_sym]
end
def display_attributes
[
{ name: "name", value: name, editable: true },
{ name: "address", value: address_string, editable: true },
{ name: "telephone_number", value: phone, editable: true },
{ name: "type", value: display_provider_type, editable: false },
{ name: "rent_periods", value: rent_period_labels, editable: false, format: :bullet },
{ name: "Owns housing stock", value: holds_own_stock ? "Yes" : "No", editable: false },
{ name: "other_stock_owners", value: other_stock_owners, editable: false },
{ name: "managing_agents", value: managing_agents, editable: false },
{ name: "data_protection_agreement", value: data_protection_agreement_string, editable: false },
]
end
end