From 350a3f8cec5420c3a2a378156589e055c12dd132 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Mon, 23 Jan 2023 17:53:13 +0000 Subject: [PATCH] feat: add sales validation to check bedsits have <=1 beds --- app/models/validations/sales/property_validations.rb | 8 ++++++++ config/locales/en.yml | 2 ++ 2 files changed, 10 insertions(+) diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 879e37ff1..3478df568 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -7,4 +7,12 @@ module Validations::Sales::PropertyValidations record.errors.add :ppostcode_full, I18n.t("validations.property.postcode.must_match_previous") end end + + def validate_propert_unit_type(record) + return if record.proptype.blank? || record.beds.blank? + + unless record.proptype != 2 || record.beds <= 1 + record.errors.add :proptype, I18n.t("validations.property.proptype.bedsits_have_max_one_bedroom") + end + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 0a4ae34de..c8b849817 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,6 +202,8 @@ en: beds: non_positive: "Number of bedrooms has to be greater than 0" over_max: "Number of bedrooms cannot be more than 12" + proptype: + bedsits_have_max_one_bedroom: "Properties with 2 or more bedrooms cannot be bedsits" postcode: must_match_previous: "Buyer's last accommodation and discounted ownership postcodes must match"