From 9748156c7493d76d18f9aa6c056f614c01273402 Mon Sep 17 00:00:00 2001 From: Carolyn Date: Mon, 17 Mar 2025 12:16:34 +0000 Subject: [PATCH] validate staircasing dates --- .../sales/sale_information_validations.rb | 23 +++++++++++++++++++ .../validations/sales/sale_information.en.yml | 9 ++++++++ 2 files changed, 32 insertions(+) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 3ddecaedb..96aac5727 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -41,6 +41,29 @@ module Validations::Sales::SaleInformationValidations if record.initialpurchase < Time.zone.local(1980, 1, 1) record.errors.add :initialpurchase, I18n.t("validations.sales.sale_information.initialpurchase.must_be_after_1980") end + + if record.initialpurchase > record.saledate + record.errors.add :initialpurchase, I18n.t("validations.sales.sale_information.initialpurchase.must_be_before_saledate") + record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_after_initial_purchase_date") + end + end + + def validate_staircasing_last_transaction_date(record) + return unless record.lasttransaction + + if record.lasttransaction < Time.zone.local(1980, 1, 1) + record.errors.add :lasttransaction, I18n.t("validations.sales.sale_information.lasttransaction.must_be_after_1980") + end + + if record.lasttransaction > record.saledate + record.errors.add :lasttransaction, I18n.t("validations.sales.sale_information.lasttransaction.must_be_before_saledate") + record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_after_last_transaction_date") + end + + if record.initialpurchase.present? && record.lasttransaction < record.initialpurchase + record.errors.add :initialpurchase, I18n.t("validations.sales.sale_information.initialpurchase.must_be_before_last_transaction") + record.errors.add :lasttransaction, I18n.t("validations.sales.sale_information.lasttransaction.must_be_after_initial_purchase") + end end def validate_previous_property_unit_type(record) diff --git a/config/locales/validations/sales/sale_information.en.yml b/config/locales/validations/sales/sale_information.en.yml index fecdb4a13..3c39608cc 100644 --- a/config/locales/validations/sales/sale_information.en.yml +++ b/config/locales/validations/sales/sale_information.en.yml @@ -16,11 +16,20 @@ en: must_be_after_exdate: "Sale completion date must be after contract exchange date." must_be_less_than_1_year_from_exdate: "Sale completion date must be less than 1 year after contract exchange date." mortgage_used_year: "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for the selected year." + must_be_after_initial_purchase_date: "Sale completion date for a staircasing transaction must be after the date of the initial purchase of a share." + must_be_after_last_transaction_date: "Sale completion date must be after the date of the last staircasing transaction." + exdate: must_be_before_saledate: "Contract exchange date must be before sale completion date." must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before sale completion date." initialpurchase: must_be_after_1980: "The initial purchase date must be after January 1, 1980." + must_be_before_last_transaction: "The initial purchase date must be before the last staircasing transaction date." + must_be_before_saledate: "The initial purchase date must be before the date of this sale." + lasttransaction: + must_be_after_1980: "The last staircasing transaction date must be after January 1, 1980." + must_be_after_initial_purchase: "The last staircasing transaction date must be after the initial purchase date." + must_be_before_saledate: "The last staircasing transaction date must be before the date of this sale." fromprop: previous_property_type_bedsit: "A bedsit cannot have more than 1 bedroom." frombeds: