From 6be860db286889e149725e43eee6db39b0c19466 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:32:19 +0000 Subject: [PATCH 1/3] CLDC-868 purchase price validations PO review (#1285) * feat: wip behaviour * feat: hide in cya * feat: show in cya * feat: purchase price range service and rake task * feat: fix hodate validation and use purchase price ranges * db:update * feat: more saledate -> exdate fixing * feat: add min and max conditional text * refactor: linting * refactor: remove duplicated behaviour * refactor: linting * feat: update tests * test: add validation tests * test: add purchase price rangeimport service tests * refactor: linting * feat: allow translation text and title text to display currency formatting even when not a log field * feat: use i18n * feat: update i18n * refactor: pratical -> practical * refactor: linting * refactor: revert unnecessary change * feat: respond to PR comments * tests: update after merge * feat: improve currency interruption screen display * feat: update docs * feat: fix typo * feat: missing end after merge * feat: respond to PR comments * feat: add soft validation to beds and la pages * db:update * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: revert saledate/exdate work * feat: PO comment responses * tests: update * refactor: linting * refactor: simplification * refactor: railsification * test: fix * refactor: use number_to_currency units * refactor: remove duplicated copy * db:update * feat: add value check for discounted and outright sale * feat: rename files * test: update * test: update * test: update * db: update --- ...ed_ownership_value_check.rb => about_price_value_check.rb} | 4 ++-- ...ed_ownership_value_check.rb => about_price_value_check.rb} | 2 +- .../form/sales/subsections/discounted_ownership_scheme.rb | 1 + app/models/form/sales/subsections/outright_sale.rb | 1 + app/models/form/sales/subsections/property_information.rb | 4 ++-- app/models/form/sales/subsections/shared_ownership_scheme.rb | 2 +- .../sales/subsections/discounted_ownership_scheme_spec.rb | 1 + spec/models/form/sales/subsections/outright_sale_spec.rb | 1 + .../form/sales/subsections/property_information_spec.rb | 4 ++-- spec/models/form_handler_spec.rb | 4 ++-- 10 files changed, 14 insertions(+), 10 deletions(-) rename app/models/form/sales/pages/{about_price_shared_ownership_value_check.rb => about_price_value_check.rb} (84%) rename app/models/form/sales/questions/{about_price_shared_ownership_value_check.rb => about_price_value_check.rb} (85%) diff --git a/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb b/app/models/form/sales/pages/about_price_value_check.rb similarity index 84% rename from app/models/form/sales/pages/about_price_shared_ownership_value_check.rb rename to app/models/form/sales/pages/about_price_value_check.rb index 5b668006a..94df02243 100644 --- a/app/models/form/sales/pages/about_price_shared_ownership_value_check.rb +++ b/app/models/form/sales/pages/about_price_value_check.rb @@ -1,4 +1,4 @@ -class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page +class Form::Sales::Pages::AboutPriceValueCheck < ::Form::Page def initialize(id, hsh, subsection) super @depends_on = [ @@ -34,7 +34,7 @@ class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page def questions @questions ||= [ - Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self), + Form::Sales::Questions::AboutPriceValueCheck.new(nil, nil, self), ] end end diff --git a/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb b/app/models/form/sales/questions/about_price_value_check.rb similarity index 85% rename from app/models/form/sales/questions/about_price_shared_ownership_value_check.rb rename to app/models/form/sales/questions/about_price_value_check.rb index 6758b68a3..2b51cd7fb 100644 --- a/app/models/form/sales/questions/about_price_shared_ownership_value_check.rb +++ b/app/models/form/sales/questions/about_price_value_check.rb @@ -1,4 +1,4 @@ -class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Question +class Form::Sales::Questions::AboutPriceValueCheck < ::Form::Question def initialize(id, hsh, page) super @id = "value_value_check" diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 74e408cfd..a44f10ee9 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -14,6 +14,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), Form::Sales::Pages::GrantValueCheck.new(nil, nil, self), Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_outright_ownership", nil, self), + Form::Sales::Pages::AboutPriceValueCheck.new("about_price_discounted_ownership_value_check", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_discounted_ownership", nil, self), Form::Sales::Pages::MortgageValueCheck.new("discounted_ownership_mortgage_used_mortgage_value_check", nil, self), diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 69f77c4b2..256c1c8dc 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -9,6 +9,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::PurchasePriceOutrightOwnership.new("purchase_price_outright_sale", nil, self), + Form::Sales::Pages::AboutPriceValueCheck.new("about_price_outright_sale_value_check", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_outright_sale", nil, self), Form::Sales::Pages::MortgageValueCheck.new("outright_sale_mortgage_used_mortgage_value_check", nil, self), Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self), diff --git a/app/models/form/sales/subsections/property_information.rb b/app/models/form/sales/subsections/property_information.rb index eb057c48c..a43607d7c 100644 --- a/app/models/form/sales/subsections/property_information.rb +++ b/app/models/form/sales/subsections/property_information.rb @@ -9,13 +9,13 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), - Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_bedrooms_value_check", nil, self), + Form::Sales::Pages::AboutPriceValueCheck.new("about_price_bedrooms_value_check", nil, self), Form::Sales::Pages::PropertyUnitType.new(nil, nil, self), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_property_type_value_check", nil, self), Form::Sales::Pages::PropertyBuildingType.new(nil, nil, self), Form::Sales::Pages::Postcode.new(nil, nil, self), Form::Sales::Pages::PropertyLocalAuthority.new(nil, nil, self), - Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_la_value_check", nil, self), + Form::Sales::Pages::AboutPriceValueCheck.new("about_price_la_value_check", nil, self), Form::Sales::Pages::PropertyWheelchairAccessible.new(nil, nil, self), ] end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 3012d2a69..1f0cd6450 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -22,7 +22,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self), Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self), - Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new("about_price_shared_ownership_value_check", nil, self), + Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self), Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb index 12cf9b38a..5d1d30037 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -20,6 +20,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model about_price_not_rtb grant_value_check purchase_price_outright_ownership + about_price_discounted_ownership_value_check discounted_ownership_deposit_and_mortgage_value_check_after_value_and_discount mortgage_used_discounted_ownership discounted_ownership_mortgage_used_mortgage_value_check diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb index 47c062478..b7b0dc846 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/spec/models/form/sales/subsections/outright_sale_spec.rb @@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do expect(outright_sale.pages.map(&:id)).to eq( %w[ purchase_price_outright_sale + about_price_outright_sale_value_check mortgage_used_outright_sale outright_sale_mortgage_used_mortgage_value_check mortgage_amount_outright_sale diff --git a/spec/models/form/sales/subsections/property_information_spec.rb b/spec/models/form/sales/subsections/property_information_spec.rb index c9ab36136..e65e8dd36 100644 --- a/spec/models/form/sales/subsections/property_information_spec.rb +++ b/spec/models/form/sales/subsections/property_information_spec.rb @@ -15,13 +15,13 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do expect(property_information.pages.map(&:id)).to eq( %w[ property_number_of_bedrooms - about_price_shared_ownership_bedrooms_value_check + about_price_bedrooms_value_check property_unit_type monthly_charges_property_type_value_check property_building_type property_postcode property_local_authority - about_price_shared_ownership_la_value_check + about_price_la_value_check property_wheelchair_accessible ], ) diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 17ebd4db0..fb7bad4b2 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -54,14 +54,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(180) + expect(form.pages.count).to eq(182) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(180) + expect(form.pages.count).to eq(182) expect(form.name).to eq("2021_2022_sales") end end From 5f5204cbcb2c1620c7d14112c3f2444f572e075a Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 24 Feb 2023 12:33:35 +0000 Subject: [PATCH 2/3] feat: align with saledate validation structure --- app/models/validations/date_validations.rb | 60 +++++++++++----------- config/initializers/feature_toggle.rb | 2 +- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 1884560b7..d21311210 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -1,5 +1,6 @@ module Validations::DateValidations include Validations::SharedValidations + include CollectionTimeHelper def validate_property_major_repairs(record) date_valid?("mrcdate", record) @@ -33,14 +34,8 @@ module Validations::DateValidations def validate_startdate(record) return unless record.startdate && date_valid?("startdate", record) - created_at = record.created_at || Time.zone.now - - if created_at >= previous_collection_end_date && !record.startdate.between?(current_collection_start_date, next_collection_start_date) - record.errors.add :startdate, I18n.t("validations.date.outside_collection_window.not_crossover_period", current_collection: "#{current_collection_start_suffix}/#{current_collection_start_suffix + 1}", current_collection_start_year: current_collection_start_date.year, current_collection_end_year: current_collection_end_date.year) - end - - if created_at < previous_collection_end_date && !record.startdate.between?(previous_collection_start_date, next_collection_start_date) - record.errors.add :startdate, I18n.t("validations.date.outside_collection_window.crossover_period", previous_collection: "#{previous_collection_start_suffix}/#{previous_collection_start_suffix + 1}", current_collection: "#{current_collection_start_suffix}/#{current_collection_start_suffix + 1}", previous_collection_start_year: previous_collection_start_date.year, current_collection_end_year: current_collection_end_date.year) + unless record.startdate.between?(current_collection_start_date, active_collection_end_date) + record.errors.add :startdate, validation_error_message end if FeatureToggle.startdate_two_week_validation_enabled? && record.startdate > Time.zone.today + 14 @@ -68,32 +63,35 @@ module Validations::DateValidations private - def previous_collection_start_suffix - previous_collection_start_date.year % 100 - end - - def current_collection_start_suffix - current_collection_start_date.year % 100 - end - - def previous_collection_start_date - FormHandler.instance.lettings_forms["previous_lettings"].start_date - end - - def previous_collection_end_date - FormHandler.instance.lettings_forms["previous_lettings"].end_date - end + def active_collection_end_date + if FeatureToggle.startdate_next_collection_year_validation_enabled? + next_collection_end_date - def current_collection_start_date - FormHandler.instance.lettings_forms["current_lettings"].start_date - end - - def current_collection_end_date - FormHandler.instance.lettings_forms["current_lettings"].end_date + else + current_collection_end_date + end end - def next_collection_start_date - FormHandler.instance.lettings_forms["next_lettings"].start_date + def validation_error_message + start_date = current_collection_start_date + if FeatureToggle.startdate_next_collection_year_validation_enabled? + I18n.t( + "validations.setup.startdate.current_and_next_financial_year", + current_start_year_short: start_date.strftime("%y"), + current_end_year_short: current_collection_end_date.strftime("%y"), + current_start_year_long: start_date.strftime("%Y"), + next_end_year_short: next_collection_end_date.strftime("%y"), + next_end_year_long: next_collection_end_date.strftime("%Y"), + ) + else + I18n.t( + "validations.setup.startdate.current_financial_year", + current_start_year_short: start_date.strftime("%y"), + current_end_year_short: current_collection_end_date.strftime("%y"), + current_start_year_long: start_date.strftime("%Y"), + current_end_year_long: current_collection_end_date.strftime("%Y"), + ) + end end def is_rsnvac_first_let?(record) diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index a7651919f..54a6879f5 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -4,7 +4,7 @@ class FeatureToggle Rails.env.production? || Rails.env.test? || Rails.env.staging? end - def self.startdate_collection_window_validation_enabled? + def self.startdate_next_collection_year_validation_enabled? Rails.env.production? || Rails.env.test? || Rails.env.staging? end From d628fdc2ae60c054bbe87effade2308c667e03fe Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 24 Feb 2023 12:35:02 +0000 Subject: [PATCH 3/3] refactor: naming --- app/models/validations/date_validations.rb | 4 ++-- config/initializers/feature_toggle.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index d21311210..5fd99fd89 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -64,7 +64,7 @@ module Validations::DateValidations private def active_collection_end_date - if FeatureToggle.startdate_next_collection_year_validation_enabled? + if FeatureToggle.startdate_collection_window_validation_enabled? next_collection_end_date else @@ -74,7 +74,7 @@ private def validation_error_message start_date = current_collection_start_date - if FeatureToggle.startdate_next_collection_year_validation_enabled? + if FeatureToggle.startdate_collection_window_validation_enabled? I18n.t( "validations.setup.startdate.current_and_next_financial_year", current_start_year_short: start_date.strftime("%y"), diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index 54a6879f5..a7651919f 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -4,7 +4,7 @@ class FeatureToggle Rails.env.production? || Rails.env.test? || Rails.env.staging? end - def self.startdate_next_collection_year_validation_enabled? + def self.startdate_collection_window_validation_enabled? Rails.env.production? || Rails.env.test? || Rails.env.staging? end