From e522ebdeae125ad7d104aeed0507bcbdee847b10 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 25 Jan 2023 16:25:16 +0000 Subject: [PATCH] feat: add one year gap exchange/completion validations --- .../validations/sales/sale_information_validations.rb | 7 ++++++- config/locales/en.yml | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index aa6cbe484..89f51fb84 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -15,13 +15,18 @@ module Validations::Sales::SaleInformationValidations end end - def validate_exchange_date_before_completion_date(record) + def validate_exchange_and_completion_date(record) return unless record.exdate && record.saledate if record.exdate > record.saledate record.errors.add :exdate, I18n.t("validations.sale_information.completion_exchange.exchange_before_completion") record.errors.add :saledate, I18n.t("validations.sale_information.completion_exchange.completion_after_exchange") end + + if record.exdate < record.saledate - 1.year + record.errors.add :exdate, I18n.t("validations.sale_information.completion_exchange.exchange_after_one_year_before_completion") + record.errors.add :saledate, I18n.t("validations.sale_information.completion_exchange.completion_before_one_year_after_exchange") + end end def validate_previous_property_unit_type(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index f525a62df..3064a9171 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -422,7 +422,8 @@ en: completion_exchange: exchange_before_completion: "Exchange date must be before completion date" completion_after_exchange: "Completion date must be after exchange date" - + exchange_after_one_year_before_completion: "Exchange date must be less than 1 year before completion date" + completion_before_one_year_after_exchange: "Completion date must be less than 1 year after exchange date" soft_validations: net_income: title_text: "Net income is outside the expected range based on the lead tenant’s working situation"