diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 1e7ae0efb..5656898bc 100644 --- a/.github/workflows/review_pipeline.yml +++ b/.github/workflows/review_pipeline.yml @@ -72,6 +72,9 @@ jobs: runs-on: ubuntu-latest environment: staging needs: [postgres, redis] + permissions: + issues: write + pull-requests: write steps: - name: Checkout code diff --git a/Gemfile b/Gemfile index b20b7fe97..f77a70899 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem "byebug", platforms: %i[mri mingw x64_mingw] gem "dotenv-rails" + gem "factory_bot_rails" gem "pry-byebug" gem "parallel_tests" @@ -90,7 +91,6 @@ end group :test do gem "capybara", require: false gem "capybara-lockstep" - gem "factory_bot_rails" gem "faker" gem "rspec-rails", require: false gem "selenium-webdriver", require: false diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 8478d06e7..be0abae20 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -1,16 +1,26 @@ module CollectionTimeHelper + def collection_start_year(date) + window_end_date = Time.zone.local(date.year, 4, 1) + date < window_end_date ? date.year - 1 : date.year + end + def current_collection_start_year - today = Time.zone.now - window_end_date = Time.zone.local(today.year, 4, 1) - today < window_end_date ? today.year - 1 : today.year + collection_start_year(Time.zone.now) end def collection_start_date(date) - window_end_date = Time.zone.local(date.year, 4, 1) - date < window_end_date ? Time.zone.local(date.year - 1, 4, 1) : Time.zone.local(date.year, 4, 1) + Time.zone.local(collection_start_year(date), 4, 1) end def current_collection_start_date Time.zone.local(current_collection_start_year, 4, 1) end + + def collection_end_date(date) + Time.zone.local(collection_start_year(date) + 1, 3, 31) + end + + def current_collection_end_date + Time.zone.local(current_collection_start_year + 1, 3, 31) + end end diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index a1875081c..7f906b4ea 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -27,4 +27,12 @@ module FiltersHelper organisation_options = user.support? ? Organisation.all : [user.organisation] + user.organisation.managing_agents [OpenStruct.new(id: "", name: "Select an option")] + organisation_options.map { |org| OpenStruct.new(id: org.id, name: org.name) } end + + def collection_year_options + if FeatureToggle.collection_2023_2024_year_enabled? + { "2023": "2023/24", "2022": "2022/23", "2021": "2021/22" } + else + { "2022": "2022/23", "2021": "2021/22" } + end + end end diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index f297de2ff..f4f1d51dd 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -39,7 +39,9 @@ module TasklistHelper def review_log_text(log) if log.collection_period_open? - "You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(log)} until #{log.form.end_date.to_formatted_s(:govuk_date)}.".html_safe + link = log.sales? ? review_sales_log_path(id: log, sales_log: true) : review_lettings_log_path(log) + + "You can #{govuk_link_to 'review and make changes to this log', link} until #{log.form.end_date.to_formatted_s(:govuk_date)}.".html_safe else "This log is from the #{log.form.start_date.year}/#{log.form.start_date.year + 1} collection window, which is now closed." end diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 96b937ab4..7d664e48f 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -45,6 +45,9 @@ module DerivedVariables::LettingsLogVariables self.underoccupation_benefitcap = 2 if collection_start_year == 2021 self.referral = 1 self.waityear = 2 + self.offered = 0 + self.voiddate = startdate + self.first_time_property_let_as_social_housing = 0 if is_general_needs? # fixed term self.prevten = 32 if managing_organisation&.provider_type == "PRP" @@ -60,7 +63,6 @@ module DerivedVariables::LettingsLogVariables if is_supported_housing? && location self.wchair = location.mobility_type_before_type_cast == "W" ? 1 : 2 end - self.voiddate = startdate if is_renewal? self.vacdays = property_vacant_days set_housingneeds_fields if housingneeds? diff --git a/app/models/form/lettings/questions/working_situation1.rb b/app/models/form/lettings/questions/working_situation1.rb index 866271f4d..20f5dc984 100644 --- a/app/models/form/lettings/questions/working_situation1.rb +++ b/app/models/form/lettings/questions/working_situation1.rb @@ -11,8 +11,8 @@ class Form::Lettings::Questions::WorkingSituation1 < ::Form::Question end ANSWER_OPTIONS = { - "2" => { "value" => "Part-time – Less than 30 hours" }, "1" => { "value" => "Full-time – 30 hours or more" }, + "2" => { "value" => "Part-time – Less than 30 hours" }, "7" => { "value" => "Full-time student" }, "3" => { "value" => "In government training into work, such as New Deal" }, "4" => { "value" => "Jobseeker" }, diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 66f622270..02236f70b 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -70,6 +70,14 @@ class LettingsLog < Log collection_start_year end + def lettings? + true + end + + def sales? + false + end + def form_name return unless startdate @@ -481,10 +489,6 @@ class LettingsLog < Log location.type_of_unit_before_type_cast if location end - def lettings? - true - end - def rent_type_detail form.get_question("rent_type", self)&.label_from_value(rent_type) end diff --git a/app/models/log.rb b/app/models/log.rb index 1b43fd1cb..0cd3add92 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -43,6 +43,10 @@ class Log < ApplicationRecord false end + def sales? + false + end + def ethnic_refused? ethnic_group == 17 end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index add706f7c..6ed653955 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -38,6 +38,14 @@ class SalesLog < Log OPTIONAL_FIELDS = %w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze + def lettings? + false + end + + def sales? + true + end + def startdate saledate end diff --git a/app/services/bulk_upload/lettings/row_parser.rb b/app/services/bulk_upload/lettings/row_parser.rb index bf1f62eba..005d5caf9 100644 --- a/app/services/bulk_upload/lettings/row_parser.rb +++ b/app/services/bulk_upload/lettings/row_parser.rb @@ -147,7 +147,7 @@ class BulkUpload::Lettings::RowParser validate :validate_nulls validate :validate_relevant_collection_window validate :validate_la_with_local_housing_referral - validate :validate_cannot_be_la_referral_if_general_needs + validate :validate_cannot_be_la_referral_if_general_needs_and_la validate :validate_leaving_reason_for_renewal validate :validate_lettings_type_matches_bulk_upload validate :validate_only_one_housing_needs_type @@ -219,8 +219,8 @@ private end end - def validate_cannot_be_la_referral_if_general_needs - if field_78 == 4 && bulk_upload.general_needs? + def validate_cannot_be_la_referral_if_general_needs_and_la + if field_78 == 4 && bulk_upload.general_needs? && owning_organisation && owning_organisation.la? errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la") end end diff --git a/app/services/exports/lettings_log_export_constants.rb b/app/services/exports/lettings_log_export_constants.rb index 332f22550..3ae7d71fa 100644 --- a/app/services/exports/lettings_log_export_constants.rb +++ b/app/services/exports/lettings_log_export_constants.rb @@ -7,13 +7,6 @@ module Exports::LettingsLogExportConstants csv: 2, }.freeze - QUARTERS = { - 0 => "jan_mar", - 1 => "apr_jun", - 2 => "jul_sep", - 3 => "oct_dec", - }.freeze - EXPORT_FIELDS = Set[ "armedforces", "beds", diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index fb985f931..197e0ed4b 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -1,6 +1,7 @@ module Exports class LettingsLogExportService include Exports::LettingsLogExportConstants + include CollectionTimeHelper def initialize(storage_service, logger = Rails.logger) @storage_service = storage_service @@ -66,11 +67,11 @@ module Exports return unless lettings_log.startdate collection_start = lettings_log.collection_start_year - month = lettings_log.startdate.month - quarter = QUARTERS[(month - 1) / 3] + start_month = collection_start_date(lettings_log.startdate).strftime("%b") + end_month = collection_end_date(lettings_log.startdate).strftime("%b") base_number_str = "f#{base_number.to_s.rjust(4, '0')}" increment_str = "inc#{increment.to_s.rjust(4, '0')}" - "core_#{collection_start}_#{collection_start + 1}_#{quarter}_#{base_number_str}_#{increment_str}" + "core_#{collection_start}_#{collection_start + 1}_#{start_month}_#{end_month}_#{base_number_str}_#{increment_str}".downcase end def write_export_archive(export, lettings_logs) diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb index a95b577bd..bc46c89d8 100644 --- a/app/views/form/review.html.erb +++ b/app/views/form/review.html.erb @@ -1,9 +1,18 @@ -<% content_for :title, "Review lettings log" %> -<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - "Log #{@log.id}" => "/lettings-logs/#{@log.id}", - "Review lettings log" => "", -}) %> +<% if @log.sales? %> + <% content_for :title, "Review sales log" %> + <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { + "Logs" => "/logs", + "Log #{@log.id}" => "/sales-logs/#{@log.id}", + "Review sales log" => "", + }) %> +<% else %> + <% content_for :title, "Review lettings log" %> + <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { + "Logs" => "/logs", + "Log #{@log.id}" => "/lettings-logs/#{@log.id}", + "Review lettings log" => "", + }) %> +<% end %>