diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8a9b7dbc1..94a4e1e60 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-09-26 11:37:04 UTC using RuboCop version 1.56.3. +# on 2023-10-05 14:45:57 UTC using RuboCop version 1.56.4. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,14 +14,6 @@ FactoryBot/AssociationStyle: Exclude: - 'spec/factories/projects.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'spec/steps/pafs_core/flood_protection_outcomes_details_spec.rb' - # Offense count: 7 # Configuration parameters: AllowComments, AllowEmptyLambdas. Lint/EmptyBlock: @@ -29,14 +21,6 @@ Lint/EmptyBlock: - 'spec/factories/steps.rb' - 'spec/helpers/pafs_core/application_helper_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopDisableDirective: - Exclude: - - 'spec/steps/pafs_core/coastal_erosion_protection_outcomes_detail_spec.rb' - - 'spec/steps/pafs_core/flood_protection_outcomes_details_spec.rb' - - 'spec/steps/pafs_core/funding_sources_and_spending_detail_spec.rb' - # Offense count: 18 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: @@ -52,7 +36,7 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 17 -# Offense count: 31 +# Offense count: 33 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 234 @@ -67,7 +51,7 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 17 -# Offense count: 662 +# Offense count: 661 # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. # SupportedStyles: snake_case, normalcase, non_integer # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 @@ -118,11 +102,11 @@ RSpec/MessageSpies: - 'spec/services/pafs_core/file_storage_service_spec.rb' - 'spec/steps/pafs_core/funding_calculator_step_spec.rb' -# Offense count: 213 +# Offense count: 214 RSpec/MultipleExpectations: Max: 9 -# Offense count: 66 +# Offense count: 68 # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 19 @@ -223,7 +207,7 @@ Rails/InverseOf: - 'app/models/pafs_core/funding_value.rb' - 'app/models/pafs_core/user.rb' -# Offense count: 20 +# Offense count: 21 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Include. # Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb @@ -233,6 +217,7 @@ Rails/Output: - 'lib/pafs_core/data_migration/export_to_pol.rb' - 'lib/pafs_core/data_migration/generate_funding_contributor_fcerm.rb' - 'lib/pafs_core/data_migration/move_funding_sources.rb' + - 'lib/pafs_core/data_migration/remove_previous_years.rb' - 'lib/pafs_core/data_migration/update_areas.rb' - 'lib/pafs_core/data_migration/update_projects.rb' - 'lib/pafs_core/files.rb' diff --git a/Gemfile.lock b/Gemfile.lock index 5330717bb..173b5a821 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -266,7 +266,7 @@ GEM faraday (>= 1, < 3) sawyer (~> 0.9) parallel (1.23.0) - parser (3.2.2.3) + parser (3.2.2.4) ast (~> 2.4.1) racc pg (1.5.4) @@ -346,7 +346,7 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - rubocop (1.56.3) + rubocop (1.56.4) base64 (~> 0.1.1) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -364,7 +364,7 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.24.0) rubocop (~> 1.33) - rubocop-rails (2.21.1) + rubocop-rails (2.21.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) @@ -409,7 +409,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8.2) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) vcr (6.2.0) webmock (3.19.1) addressable (>= 2.8.0) diff --git a/app/helpers/pafs_core/projects_helper.rb b/app/helpers/pafs_core/projects_helper.rb index f47f7be4a..fc7d5cfd9 100644 --- a/app/helpers/pafs_core/projects_helper.rb +++ b/app/helpers/pafs_core/projects_helper.rb @@ -104,11 +104,19 @@ def str_year(year) end def formatted_financial_year(year) - "#{year} to #{year + 1}" + if year.negative? + t("previous_years_label") + else + "#{year} to #{year + 1}" + end end def formatted_financial_month_and_year(year) - "April #{year} to March #{year + 1}" + if year.negative? + t("previous_years_label") + else + "April #{year} to March #{year + 1}" + end end def urgency_flag(project) diff --git a/app/presenters/pafs_core/camc3_presenter.rb b/app/presenters/pafs_core/camc3_presenter.rb index 4d307ac61..983ea077f 100644 --- a/app/presenters/pafs_core/camc3_presenter.rb +++ b/app/presenters/pafs_core/camc3_presenter.rb @@ -207,7 +207,7 @@ def attributes attr_accessor :project, :fcerm1_presenter, :pf_calculator_presenter, :fcerm1_mapper, :funding_sources_mapper def financial_years - Time.zone.today.uk_financial_year..project.project_end_financial_year + [-1] + (2015..project.project_end_financial_year).to_a end end end diff --git a/app/services/pafs_core/program_upload_service.rb b/app/services/pafs_core/program_upload_service.rb index 649bedb26..882a608d7 100644 --- a/app/services/pafs_core/program_upload_service.rb +++ b/app/services/pafs_core/program_upload_service.rb @@ -145,7 +145,7 @@ def build_project_from_row(row) if range # handle ranges start_column = column - years = (Time.zone.today.uk_financial_year..2027) + years = [-1].concat((2015..2027).to_a) values = [] years.each_with_index do |_year, i| cell = row[start_column + i] diff --git a/app/services/pafs_core/remove_previous_years_service.rb b/app/services/pafs_core/remove_previous_years_service.rb new file mode 100644 index 000000000..47a754743 --- /dev/null +++ b/app/services/pafs_core/remove_previous_years_service.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module PafsCore + class RemovePreviousYearsService + attr_reader :project, :current_year + + def initialize(project) + @project = project + @current_year = Time.zone.today.uk_financial_year + end + + def run + return if project.state.state == "submitted" + + ActiveRecord::Base.transaction do + prune_years(:funding_values) + prune_years(:flood_protection_outcomes) + prune_years(:flood_protection2040_outcomes) + prune_years(:coastal_erosion_protection_outcomes) + end + end + + private + + def prune_years(annual_attribute) + project.send(annual_attribute).where("financial_year < ?", current_year).destroy_all + end + end +end diff --git a/app/services/pafs_core/spreadsheet/contributors/coerce/financial_year.rb b/app/services/pafs_core/spreadsheet/contributors/coerce/financial_year.rb index da989e1d6..7bee44534 100644 --- a/app/services/pafs_core/spreadsheet/contributors/coerce/financial_year.rb +++ b/app/services/pafs_core/spreadsheet/contributors/coerce/financial_year.rb @@ -6,6 +6,8 @@ module Contributors module Coerce class FinancialYear < Base def perform + return -1 if value == "Previous years" + raise("unknown year") if matches.nil? matches[0] diff --git a/app/services/pafs_core/spreadsheet/contributors/export.rb b/app/services/pafs_core/spreadsheet/contributors/export.rb index dcee3bfea..394a79e52 100644 --- a/app/services/pafs_core/spreadsheet/contributors/export.rb +++ b/app/services/pafs_core/spreadsheet/contributors/export.rb @@ -34,6 +34,8 @@ def generate private def financial_year(value) + return "Previous years" if value == -1 + "#{value} - #{value + 1}" end diff --git a/app/services/pafs_core/spreadsheet_service.rb b/app/services/pafs_core/spreadsheet_service.rb index 05e98d916..998719c66 100644 --- a/app/services/pafs_core/spreadsheet_service.rb +++ b/app/services/pafs_core/spreadsheet_service.rb @@ -131,7 +131,7 @@ def add_project_to_sheet(sheet, project, row_no) if range start_column = column_index(col[:column]) - years = (Time.zone.today.uk_financial_year..2027) + years = [-1].concat((2015..2027).to_a) years.each_with_index do |year, i| value = use_value ? project.send(name, year) : 0 sheet[row_no][start_column + i].change_contents(value) diff --git a/app/views/pafs_core/projects/steps/coastal_erosion_protection_outcomes_summary.html.erb b/app/views/pafs_core/projects/steps/coastal_erosion_protection_outcomes_summary.html.erb index 26c273e13..28012a4be 100644 --- a/app/views/pafs_core/projects/steps/coastal_erosion_protection_outcomes_summary.html.erb +++ b/app/views/pafs_core/projects/steps/coastal_erosion_protection_outcomes_summary.html.erb @@ -28,7 +28,6 @@
<% @project.current_coastal_erosion_protection_outcomes.each do |cepo| %> - <% next if cepo.financial_year == -1 %>