diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 83d7cbbb0..54d49b7e0 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -57,8 +57,8 @@ module Validations::Sales::SaleInformationValidations end def validate_grant_amount(record) - return unless record.grant return unless record.saledate && record.form.start_year_after_2024? + return unless record.grant && (record.type == 8 || record.type == 21) unless record.grant.between?(9_000, 16_000) record.errors.add :grant, I18n.t("validations.sale_information.grant.out_of_range") diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index aa7394f9e..a2d1de7fd 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -117,7 +117,8 @@ module Validations::Sales::SoftValidations def grant_outside_common_range? return unless grant - return unless saledate && !form.start_year_after_2024? + return unless type && saledate + return unless !form.start_year_after_2024? || type == 21 || type == 8 !grant.between?(9_000, 16_000) end diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index fadea88b9..c890afed1 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -480,7 +480,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when over the max" do - let(:record) { build(:sales_log, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 8, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } it "adds an error" do sale_information_validator.validate_grant_amount(record) @@ -490,7 +490,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when under the min" do - let(:record) { build(:sales_log, grant: 3, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 21, grant: 3, saledate: Time.zone.local(2024, 4, 5)) } it "adds an error" do sale_information_validator.validate_grant_amount(record) @@ -500,7 +500,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when grant is blank" do - let(:record) { build(:sales_log, grant: nil, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 21, grant: nil, saledate: Time.zone.local(2024, 4, 5)) } it "does not add an error" do sale_information_validator.validate_grant_amount(record) @@ -509,8 +509,28 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end + context "when over the max and type is not RTA of social homebuy" do + let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + + it "does not add an error" do + sale_information_validator.validate_grant_amount(record) + + expect(record.errors).not_to be_present + end + end + + context "when under the min and type is not RTA of social homebuy" do + let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + + it "does not add error" do + sale_information_validator.validate_grant_amount(record) + + expect(record.errors).not_to be_present + end + end + context "with log before 2024/25 collection" do - let(:record) { build(:sales_log, grant: 3, saledate: Time.zone.local(2023, 4, 5)) } + let(:record) { build(:sales_log, type: 8, grant: 3, saledate: Time.zone.local(2023, 4, 5)) } it "does not add an error" do sale_information_validator.validate_grant_amount(record) diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 9cfe9e18b..170c474b7 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -660,6 +660,7 @@ RSpec.describe Validations::Sales::SoftValidations do describe "#grant_outside_common_range?" do it "returns true if grant is below 9000" do record.grant = 1_000 + record.type = 9 record.saledate = Time.zone.local(2024, 1, 1) expect(record).to be_grant_outside_common_range @@ -667,6 +668,7 @@ RSpec.describe Validations::Sales::SoftValidations do it "returns true if grant is above 16000" do record.grant = 100_000 + record.type = 9 record.saledate = Time.zone.local(2024, 1, 1) expect(record).to be_grant_outside_common_range @@ -674,13 +676,31 @@ RSpec.describe Validations::Sales::SoftValidations do it "returns false if grant is within expected range" do record.grant = 10_000 + record.type = 9 record.saledate = Time.zone.local(2024, 1, 1) expect(record).not_to be_grant_outside_common_range end - it "returns false for logs after 2024" do + it "returns true for logs after 2024 with RTA" do record.grant = 100_000 + record.type = 8 + record.saledate = Time.zone.local(2025, 1, 1) + + expect(record).to be_grant_outside_common_range + end + + it "returns true for logs after 2024 with socialBuy" do + record.grant = 100_000 + record.type = 21 + record.saledate = Time.zone.local(2025, 1, 1) + + expect(record).to be_grant_outside_common_range + end + + it "returns false for logs after 2024 with other type" do + record.grant = 100_000 + record.type = 9 record.saledate = Time.zone.local(2025, 1, 1) expect(record).not_to be_grant_outside_common_range