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.

255 lines
8.4 KiB

class FormHandler
include Singleton
include CollectionTimeHelper
attr_reader :forms
SALES_SECTIONS = [
Form::Sales::Sections::PropertyInformation,
Form::Sales::Sections::Household,
Form::Sales::Sections::Finances,
Form::Sales::Sections::SaleInformation,
].freeze
LETTINGS_SECTIONS = [
Form::Lettings::Sections::TenancyAndProperty,
Form::Lettings::Sections::Household,
Form::Lettings::Sections::RentAndCharges,
].freeze
def initialize
@forms = get_all_forms
end
def get_form(form)
@forms[form]
end
def current_lettings_form
forms["current_lettings"]
end
CLDC-3116 Create homepage (#2113) * feat: add blank homepage, update routing and tests * feat: add welcome message and thoroughly test routing * refactor: lint * feat: update tests * CLDC-3076: Make example dates consistent (#2107) * CLDC-3076: Make example dates consistent * Use example date even when some hint text provided already * Temp remove some date restrictions * Update to 2 line breaks * Revert "Temp remove some date restrictions" This reverts commit cd7f18f9f10957be0cbabee7665c0abe4239acb6. * Fix lettings log accessor in date question (#2117) * Fix lettings log accessor in date question * Remove hardcoded date example from mrcdate question (#2118) --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> * CLDC-3061 Add guidance page (#2121) * Add guidance page * Link to guidance from start page * feat: test home/start paths explicitly * CLDC-2253 Add collection resources (#2120) * Update collection resources, add to homepage * Add guidance link to an empty page * Update headings * Rebase fix * Update title * Update file names * Add section break * CLDC-2593 Add upcoming deadlines section (#2119) * Add upcoming deadlines section * Update the content to use the correct dates * Update content * lint * typos * CLDC-2252 Add homepage task section (#2115) * feat: wip add lettings, sales and schemes sections with correct text, counts, links and colouring * feat: add flex styling to match designs * CLDC-3076: Make example dates consistent (#2107) * CLDC-3076: Make example dates consistent * Use example date even when some hint text provided already * Temp remove some date restrictions * Update to 2 line breaks * Revert "Temp remove some date restrictions" This reverts commit cd7f18f9f10957be0cbabee7665c0abe4239acb6. * Fix lettings log accessor in date question (#2117) * Fix lettings log accessor in date question * Remove hardcoded date example from mrcdate question (#2118) --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> * feat: update breakpoints for responsive layout changes * lint: use hash lookup where possible * lint: erblinting * feat: improve formatting * Reuse govuk grid * Revert "Reuse govuk grid" This reverts commit 8c71f5d9edf261802a8a86e07c13552f51283668. * feat: test home page data boxes * refactor: lint * refactor: lint * feat: test link behaviour is correct in all user scenarios * refactor: lint * feat: update tests * feat: combine task, resources, deadlines sections --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Co-authored-by: Kat <kosiak.katrina@gmail.com> * CLDC-2255 Add homepage notifications (#2131) * feat: add notification table * feat: add notification banner, use unread gem for notification management * feat: add notifications page and remove unread_notification.rb * feat: add blank homepage, update routing and tests * feat: add welcome message and thoroughly test routing * refactor: lint * feat: update tests * CLDC-3061 Add guidance page (#2121) * Add guidance page * Link to guidance from start page * feat: test home/start paths explicitly * feat: add notification table * feat: add notification banner, use unread gem for notification management * feat: add notifications page and remove unread_notification.rb * feat: default p tag around sanitized page content * feat: add active scope * feat: use newest active unread/unauthenticated notification and update start page * feat: add tests of notification behaviour and routing and refactor * refactor: lint * feat: update Gemfile.lock * feat: add timestamps to readmark table * feat: update gemfile.lock * refactor: lint * feat: test notifications page doesn't show notifications and code simplification * feat: move notification helper methods to notifications_helper.rb --------- Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * feat: clear all no-status filters on in progress links * CLDC-2590 Add about this service section (#2124) * Add about core section * Move about core to the correct spot on start page * Update content * Add some margins --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Co-authored-by: Kat <kosiak.katrina@gmail.com>
10 months ago
def previous_lettings_form
forms["previous_lettings"]
end
def next_lettings_form
forms["next_lettings"]
end
def current_sales_form
forms["current_sales"]
end
def previous_sales_form
forms["previous_sales"]
end
def next_sales_form
forms["next_sales"]
end
def sales_forms
@sales_forms ||= {
"current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"),
"previous_sales" => Form.new(nil, previous_collection_start_year, SALES_SECTIONS, "sales"),
"next_sales" => Form.new(nil, next_collection_start_year, SALES_SECTIONS, "sales"),
"archived_sales" => Form.new(nil, previous_collection_start_year - 1, SALES_SECTIONS, "sales"),
}
if @sales_forms.count { |_name, form| Time.zone.now.between?(form.start_date, form.edit_end_date) } == 1
@sales_forms.delete("archived_sales")
end
@sales_forms
end
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
def ordered_sales_questions_for_all_years
ordered_questions = current_sales_form.questions.uniq(&:id)
all_sales_forms = forms.filter { |name, _form| name.end_with? "sales" }.values
all_questions_from_available_sales_forms = all_sales_forms.flat_map(&:questions)
deprecated_questions_by_preceding_question_id(ordered_questions, all_questions_from_available_sales_forms).each do |preceding_question_id, deprecated_question|
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
index_of_preceding_question = ordered_questions.index { |q| q.id == preceding_question_id }
ordered_questions.insert(index_of_preceding_question + 1, deprecated_question)
end
ordered_questions
end
def ordered_lettings_questions_for_all_years
ordered_questions = current_lettings_form.questions.uniq(&:id)
all_lettings_forms = forms.filter { |name, _form| name.end_with? "lettings" }.values
all_questions_from_available_lettings_forms = all_lettings_forms.flat_map(&:questions)
deprecated_questions_by_preceding_question_id(ordered_questions, all_questions_from_available_lettings_forms).each do |preceding_question_id, deprecated_question|
index_of_preceding_question = ordered_questions.index { |q| q.id == preceding_question_id }
ordered_questions.insert(index_of_preceding_question + 1, deprecated_question)
end
ordered_questions
end
def deprecated_questions_by_preceding_question_id(current_form_questions, all_questions_from_previous_forms)
current_form_question_ids = current_form_questions.map(&:id)
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
deprecated_questions = {}
all_questions_from_previous_forms.each_cons(2) do |preceding_question, question|
next if current_form_question_ids.include?(question.id) || deprecated_questions.values.map(&:id).include?(question.id)
if question.subsection.id == preceding_question.subsection.id
deprecated_questions[preceding_question.id] = question
else
last_in_preceding_subsection = current_form_questions.rindex { |q| q.subsection.id == preceding_question.subsection.id }
deprecated_questions[current_form_questions[last_in_preceding_subsection].id] = question
end
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
end
deprecated_questions
end
def lettings_forms
@lettings_forms ||= get_lettings_forms
end
def get_lettings_forms
forms = {}
directories.each do |directory|
Dir.glob("#{directory}/*.json").each do |form_path|
form = Form.new(form_path)
form_to_set = form_name_from_start_year(form.start_date.year, "lettings")
forms[form_to_set] = form if form_to_set && forms[form_to_set].blank?
end
end
if forms["previous_lettings"].blank? && current_collection_start_year >= 2022
forms["previous_lettings"] = Form.new(nil, previous_collection_start_year, LETTINGS_SECTIONS, "lettings")
end
if forms["archived_lettings"].blank? && current_collection_start_year >= 2025
forms["archived_lettings"] = Form.new(nil, previous_collection_start_year - 1, LETTINGS_SECTIONS, "lettings")
end
forms["current_lettings"] = Form.new(nil, current_collection_start_year, LETTINGS_SECTIONS, "lettings") if forms["current_lettings"].blank?
forms["next_lettings"] = Form.new(nil, next_collection_start_year, LETTINGS_SECTIONS, "lettings") if forms["next_lettings"].blank?
if forms.count { |_name, form| Time.zone.now.between?(form.start_date, form.edit_end_date) } == 1
forms.delete("archived_lettings")
end
if Rails.env.test?
forms.merge({ fake_lettings_2021: Form.new("spec/fixtures/forms/2021_2022.json"), real_lettings_2021: Form.new("config/forms/2021_2022.json") })
else
forms
end
end
def lettings_form_for_start_year(year)
lettings_forms.values.find { |form| form.start_date.year == year }
end
def sales_form_for_start_year(year)
sales_forms.values.find { |form| form.start_date.year == year }
end
def form_name_from_start_year(year, type)
form_mappings = { 0 => "current_#{type}", 1 => "previous_#{type}", -1 => "next_#{type}", 2 => "archived_#{type}" }
form_mappings[current_collection_start_year - year]
end
def start_date_of_earliest_open_collection_period
in_crossover_period? ? previous_collection_start_date : current_collection_start_date
end
def start_date_of_earliest_open_for_editing_collection_period
in_edit_crossover_period? ? previous_collection_start_date : current_collection_start_date
end
def in_crossover_period?(now: Time.zone.now)
lettings_in_crossover_period?(now:) || sales_in_crossover_period?(now:)
end
def in_edit_crossover_period?(now: Time.zone.now)
lettings_in_edit_crossover_period?(now:) || sales_in_edit_crossover_period?(now:)
end
def lettings_in_crossover_period?(now: Time.zone.now)
forms = lettings_forms.values
forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1
end
def lettings_in_edit_crossover_period?(now: Time.zone.now)
forms = lettings_forms.values
forms.count { |form| now.between?(form.start_date, form.edit_end_date) } > 1
end
def sales_in_crossover_period?(now: Time.zone.now)
forms = sales_forms.values
forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1
end
def sales_in_edit_crossover_period?(now: Time.zone.now)
forms = sales_forms.values
forms.count { |form| now.between?(form.start_date, form.edit_end_date) } > 1
end
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
def use_fake_forms!(fake_forms = nil)
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
@directories = ["spec/fixtures/forms"]
CLDC-1633 build feature csv download of sales logs (#1568) * create a method on the FormHandler that returns the sales form questions for all years in the order that they appear in the form * update csv email job to accomodate sales log export as well as lettings add to tests to reflec the changes made * write tests to cover the desired functionality of the SalesLogCsvService * create the SalesLogCsvService create a necessary method on the log to enable submission method to be included on the csv derive values for the two halves of previous postcode for export * add relevant links in the UI and pipe everything together in controllers amend organisations controller to have flexibility to download logs of either type add necessary methods to sales log controller, raising shared method to logs controller update routing for amendments and additions extract helper method to build urls for downloading logs within an organisation * correct various linter complaints and tech review suggestions * minor amendment to add old_id and reorder early columns * undo my 'clever' refactor that broke things * refactoring of csv service after some tech review and some UI testing in review app * update tests to include a test of a full export and all values in teh csv * correct minor routing error to ensure correct url is shown and tab selected after requesting csv email * update organisations controller requests spec file to cover new functionality and make a minor amendment to authentication scope in the controller after error found in testing * write request tests for the new functionality in the sales log controller, define authorisation in the controller * minor correction after rubocop's kind suggestion' * various corrections from first pass at PO, tech review, linter, etc * refactor :ordered_sales_questions_for_all_years * first pass at implementing flexible code-based form fixtures for testing * second pass * refactor all tests of :ordered_sales_questions_for_all_years to use new factories * some refactoring in the testing of the csv service * use that fact that params is always available in controllers and don't pass it around, inline some methods calls * correct minor bug to ensure that "Return to logs" link returns to the correct index page * remove reminder comments * write further tests on the manipulation of questions into the csv headers, update factories of form constituents to allow the creation of forms with richer questions * fix linter complaints * minor alterations after rebase to account for changes made on other branches * refactor after code review * tweak fixtures after rebase containing alterations to the factory defaults
2 years ago
@forms = fake_forms || get_all_forms
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
end
def use_real_forms!
@directories = ["config/forms"]
@lettings_forms = get_lettings_forms
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
@forms = get_all_forms
end
def earliest_open_collection_start_date(now: Time.zone.now)
if in_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
def earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
def lettings_earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if lettings_in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
def sales_earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if sales_in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
def years_of_available_lettings_forms
years = []
lettings_forms.each_value do |form|
years << form.start_date.year
end
years
end
def years_of_available_sales_forms
years = []
sales_forms.each_value do |form|
years << form.start_date.year
end
years
end
private
def get_all_forms
lettings_forms.merge(sales_forms)
end
def directories
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
@directories ||= Rails.env.test? ? ["spec/fixtures/forms"] : ["config/forms"]
end
end