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.

60 lines
1.6 KiB

class Form::Lettings::Questions::LocationId < ::Form::Question
def initialize(_id, hsh, page)
super("location_id", hsh, page)
@check_answer_label = "Location"
@header = header_text
@type = "radio"
@answer_options = answer_options
@inferred_answers = {
"location.name": {
"needstype": 2,
},
}
@question_number = 10
end
def answer_options
answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected?
CLDC-1911 Add form definition for 23/24 lettings (#1254) * Spike for generating form * Add remaining field mappings * Add question attributes conditionally * Display page attributes conditionally * update subsection formatting * Update section formatting * fix generator * Fix generator * Update the form handler and form to create post 2021 forms programatically * Initially generated and linted form * Cover lettings sections and subsections wiht tests * Cover age pages and questions with tests * Add reusable age questions and adjust the tests * Add a generic person age page using generic questions and adjust specs * Multiline arrays in subsections * Use generic person age page in household characteristics and remove unused pages/questions * Combine and reduce tests * Backfill duplicate rsnvac question * Backfill repeating question * Backfill repeating voiddate * Backfill repeating tenancy question * Backfill ethnic questions * Backfill reason question * Backfill prevten question * Backfill referral questions * Backfill chcharges questions * Backfill brent questions * Backfill scharge * Backfill pscharge * Backfill supcharg * Backfill tcharge * Backfill retirement value check question * Make person known questions generic * Make person gender identity questions generic * Make relationship questions generic * Make working situation questions generic * make retirement check generic * make pregnant household check generic * Make pregnancy value checks generic, again * Undo for and form handler changes * Remove generate form task and service * Remove empty headers, descriptions and initializers from pages * Fix tests * lint
2 years ago
Location.select(:id, :postcode, :name).where("startdate <= ? or startdate IS NULL",
Time.zone.today).each_with_object(answer_opts) do |location, hsh|
hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name }
hsh
end
end
def displayed_answer_options(lettings_log, _user = nil)
return {} unless lettings_log.scheme
CLDC-2140 Scheme and location updates (#1455) * feat: update scheme status so incomplete unless has active locations * feat: update scheme typeahead text * feat: reject incomplete locations * feat: show completed/incomplete locations and validate when completed == 0 * feat: improve copy * feat: change active -> completed * feat: update scheme typeahead text * feat: reject incomplete locations * feat: show completed/incomplete locations and validate when completed == 0 * feat: improve copy * feat: change to confirmed to add clarification in code * feat: update scheme typeahead text * feat: reject incomplete locations * feat: show completed/incomplete locations and validate when completed == 0 * feat: improve copy * feat: update scheme typeahead text * feat: reject incomplete locations * feat: only confirm locations if complete (old) AND save button clicked (new) * feat: add unconfirmed scope * refactor: complete -> confirm * feat: fix tests * feat: update scheme typeahead text * feat: reject incomplete locations * feat: show completed/incomplete locations and validate when completed == 0 * feat: improve copy * feat: update scheme typeahead text * feat: reject incomplete locations * feat: only confirm locations if complete (old) AND save button clicked (new) * feat: add unconfirmed scope * refactor: complete -> confirm * feat: fix tests * feat: fix more tests * feat: fix more tests * refactor: rubocop * refactor: rubocop * refactor: rubocop * feat: add tests for incomplete schemes * refactor: linting * feat: test incomplete count too * feat: test unconfirmed locations aren't options in location_id * feat: test validation * feat: test when scheme is confirmed * feat: test when scheme is confirmed for support user * feat: test when location is confirmed * refactor: linting * refactor: consistent use of factorybot or not within a file * feat: confirm locations when complete even if save button not clicked, and update tests * refactor: simplify * refactor: simplify * refactor: move location helper methods to helpers * refactor: move scheme helper methods to helpers * refactor: formatting * refactor: po response * refactor: review response
2 years ago
scheme_location_ids = lettings_log.scheme.locations.confirmed.pluck(:id)
answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) }
end
def hidden_in_check_answers?(lettings_log, _current_user = nil)
!supported_housing_selected?(lettings_log)
end
def get_extra_check_answer_value(lettings_log)
lettings_log.form.get_question("la", nil).label_from_value(lettings_log.la)
end
private
def supported_housing_selected?(lettings_log)
lettings_log.needstype == 2
end
def selected_answer_option_is_derived?(_lettings_log)
false
end
def header_text
if form.start_date && form.start_date.year >= 2023
"Which location is this letting for?"
else
"Which location is this log for?"
end
end
end