From 026a4ac56ca9c3130d901ae1fae53a6602e1e37c Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 12 Oct 2022 17:01:13 +0100 Subject: [PATCH] feat: add validation for voiddate and mrcdate when startdate changed after these have been added later --- app/models/validations/date_validations.rb | 8 ++++++++ config/locales/en.yml | 2 ++ 2 files changed, 10 insertions(+) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 18267ffdb..eeaf8e674 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -51,6 +51,14 @@ module Validations::DateValidations record.errors.add :startdate, I18n.t("validations.setup.startdate.before_scheme_end_date") end end + + if record["voiddate"].present? && (record.startdate < record["voiddate"]) + record.errors.add :startdate, I18n.t("validations.setup.startdate.after_void_date") + end + + if record["mrcdate"].present? && (record.startdate < record["mrcdate"]) + record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date") + end end private diff --git a/config/locales/en.yml b/config/locales/en.yml index ef58f0cae..8b9a12286 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -118,6 +118,8 @@ en: startdate: later_than_14_days_after: "The tenancy start date must not be later than 14 days from today’s date" before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme" + after_void_date: "Enter a tenancy start date that is after the void date" + after_major_repair_date: "Enter a tenancy start date that is after the major repair date" property: mrcdate: