From 5b74254631c5019fa378041e653072059be98732 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 26 Jan 2023 11:05:59 +0000 Subject: [PATCH] refactor: cleanup --- .../sales/sale_information_validations.rb | 12 ++++++------ config/locales/en.yml | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 77523d555..eed5a5757 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -3,7 +3,7 @@ module Validations::Sales::SaleInformationValidations return if record.saledate.blank? || record.hodate.blank? unless record.saledate > record.hodate - record.errors.add :hodate, "Practical completion or handover date must be before exchange date" + record.errors.add :hodate, I18n.t("validations.sale_information.hodate.must_be_before_exdate") end end @@ -11,13 +11,13 @@ module Validations::Sales::SaleInformationValidations return unless record.exdate && record.saledate if record.exdate > record.saledate - record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_before_saledate")) - record.errors.add(:saledate, I18n.t("validations.sale_information.saledate.must_be_after_exdate")) + record.errors.add :exdate, I18n.t("validations.sale_information.exdate.must_be_before_saledate") + record.errors.add :saledate, I18n.t("validations.sale_information.saledate.must_be_after_exdate") end - if record.saledate.to_date - record.exdate.to_date > 1.year.in_days - record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate")) - record.errors.add(:saledate, I18n.t("validations.sale_information.saledate.must_be_less_than_1_year_from_exdate")) + if record.saledate - record.exdate > 1.year + record.errors.add :exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate") + record.errors.add :saledate, I18n.t("validations.sale_information.saledate.must_be_less_than_1_year_from_exdate") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c90ad0ce8..ba300e0cb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -415,6 +415,8 @@ en: deactivation: during_deactivated_period: "The location is already deactivated during this date, please enter a different date" sale_information: + hodate: + must_be_before_exdate: "Practical completion or handover date must be before exchange date" exdate: must_be_before_saledate: "Contract exchange date must be less than 1 year before completion date" must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before completion date"