Browse Source

CLDC-3676: sales soft validations year edits

CLDC-3676-remove-all-pre-2025-validations
samyou-softwire 1 week ago
parent
commit
ee1237cdc3
  1. 44
      app/models/validations/sales/soft_validations.rb
  2. 18
      spec/models/validations/sales/soft_validations_spec.rb

44
app/models/validations/sales/soft_validations.rb

@ -2,25 +2,16 @@ module Validations::Sales::SoftValidations
include Validations::Sales::SaleInformationValidations include Validations::Sales::SaleInformationValidations
ALLOWED_INCOME_RANGES_SALES = { ALLOWED_INCOME_RANGES_SALES = {
2024 => { 1 => OpenStruct.new(soft_min: 13_400, soft_max: 150_000),
1 => OpenStruct.new(soft_min: 5000), 2 => OpenStruct.new(soft_min: 2_600, soft_max: 80_000),
2 => OpenStruct.new(soft_min: 1500), 3 => OpenStruct.new(soft_min: 2_080, soft_max: 30_000),
3 => OpenStruct.new(soft_min: 1000), 4 => OpenStruct.new(soft_min: 520, soft_max: 23_400),
5 => OpenStruct.new(soft_min: 2000), 5 => OpenStruct.new(soft_min: 520, soft_max: 80_000),
0 => OpenStruct.new(soft_min: 2000), 6 => OpenStruct.new(soft_min: 520, soft_max: 50_000),
}, 7 => OpenStruct.new(soft_min: 520, soft_max: 30_000),
2025 => { 8 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
1 => OpenStruct.new(soft_min: 13_400, soft_max: 150_000), 9 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
2 => OpenStruct.new(soft_min: 2_600, soft_max: 80_000), 0 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
3 => OpenStruct.new(soft_min: 2_080, soft_max: 30_000),
4 => OpenStruct.new(soft_min: 520, soft_max: 23_400),
5 => OpenStruct.new(soft_min: 520, soft_max: 80_000),
6 => OpenStruct.new(soft_min: 520, soft_max: 50_000),
7 => OpenStruct.new(soft_min: 520, soft_max: 30_000),
8 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
9 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
0 => OpenStruct.new(soft_min: 520, soft_max: 150_000),
},
}.freeze }.freeze
def income1_outside_soft_range_for_ecstat? def income1_outside_soft_range_for_ecstat?
@ -76,7 +67,7 @@ module Validations::Sales::SoftValidations
end end
def savings_over_soft_max? def savings_over_soft_max?
soft_max = form.start_year_2025_or_later? && type == 24 ? 200_000 : 100_000 soft_max = type == 24 ? 200_000 : 100_000
savings && savings > soft_max savings && savings > soft_max
end end
@ -145,7 +136,7 @@ module Validations::Sales::SoftValidations
def grant_outside_common_range? def grant_outside_common_range?
return unless grant && type && saledate return unless grant && type && saledate
return if form.start_year_2024_or_later? && [21, 8].include?(type) return if [21, 8].include?(type)
!grant.between?(9_000, 16_000) !grant.between?(9_000, 16_000)
end end
@ -222,10 +213,9 @@ private
def income_under_soft_min?(income, ecstat) def income_under_soft_min?(income, ecstat)
return unless income && ecstat return unless income && ecstat
income_ranges = form.start_year_2025_or_later? ? ALLOWED_INCOME_RANGES_SALES[2025] : ALLOWED_INCOME_RANGES_SALES[2024] return false unless ALLOWED_INCOME_RANGES_SALES[ecstat]
return false unless income_ranges[ecstat]
income < income_ranges[ecstat][:soft_min] income < ALLOWED_INCOME_RANGES_SALES[ecstat][:soft_min]
end end
def income1_over_soft_max_for_ecstat? def income1_over_soft_max_for_ecstat?
@ -237,11 +227,11 @@ private
end end
def income_over_soft_max?(income, ecstat) def income_over_soft_max?(income, ecstat)
return unless income && ecstat && form.start_year_2025_or_later? return unless income && ecstat
return false unless ALLOWED_INCOME_RANGES_SALES[2025][ecstat] return false unless ALLOWED_INCOME_RANGES_SALES[ecstat]
income > ALLOWED_INCOME_RANGES_SALES[2025][ecstat][:soft_max] income > ALLOWED_INCOME_RANGES_SALES[ecstat][:soft_max]
end end
def income_over_discounted_sale_soft_max?(income) def income_over_discounted_sale_soft_max?(income)

18
spec/models/validations/sales/soft_validations_spec.rb

@ -765,7 +765,7 @@ RSpec.describe Validations::Sales::SoftValidations do
it "returns true if grant is below 9000" do it "returns true if grant is below 9000" do
record.grant = 1_000 record.grant = 1_000
record.type = 9 record.type = 9
record.saledate = Time.zone.local(2024, 1, 1) record.saledate = current_collection_start_date
expect(record).to be_grant_outside_common_range expect(record).to be_grant_outside_common_range
end end
@ -773,7 +773,7 @@ RSpec.describe Validations::Sales::SoftValidations do
it "returns true if grant is above 16000" do it "returns true if grant is above 16000" do
record.grant = 100_000 record.grant = 100_000
record.type = 9 record.type = 9
record.saledate = Time.zone.local(2024, 1, 1) record.saledate = current_collection_start_date
expect(record).to be_grant_outside_common_range expect(record).to be_grant_outside_common_range
end end
@ -781,31 +781,31 @@ RSpec.describe Validations::Sales::SoftValidations do
it "returns false if grant is within expected range" do it "returns false if grant is within expected range" do
record.grant = 10_000 record.grant = 10_000
record.type = 9 record.type = 9
record.saledate = Time.zone.local(2024, 1, 1) record.saledate = current_collection_start_date
expect(record).not_to be_grant_outside_common_range expect(record).not_to be_grant_outside_common_range
end end
it "returns false for logs after 2024 with RTA" do it "returns false for logs with RTA" do
record.grant = 100_000 record.grant = 100_000
record.type = 8 record.type = 8
record.saledate = Time.zone.local(2025, 1, 1) record.saledate = current_collection_start_date
expect(record).not_to be_grant_outside_common_range expect(record).not_to be_grant_outside_common_range
end end
it "returns false for logs after 2024 with socialBuy" do it "returns false for logs with socialBuy" do
record.grant = 100_000 record.grant = 100_000
record.type = 21 record.type = 21
record.saledate = Time.zone.local(2025, 1, 1) record.saledate = current_collection_start_date
expect(record).not_to be_grant_outside_common_range expect(record).not_to be_grant_outside_common_range
end end
it "returns true for logs after 2024 with other type" do it "returns true for logs with other type" do
record.grant = 100_000 record.grant = 100_000
record.type = 9 record.type = 9
record.saledate = Time.zone.local(2025, 1, 1) record.saledate = current_collection_start_date
expect(record).to be_grant_outside_common_range expect(record).to be_grant_outside_common_range
end end

Loading…
Cancel
Save