Browse Source

CLDC-3174 Validate stairowned is not equal stairbought (#2198)

* Validate stairowned is not equal stairbought

* Update BU tests

* Update error message
pull/2205/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
869bb45438
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      app/models/validations/sales/financial_validations.rb
  2. 1
      config/locales/en.yml
  3. 47
      spec/models/validations/sales/financial_validations_spec.rb
  4. 2
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

10
app/models/validations/sales/financial_validations.rb

@ -52,6 +52,16 @@ module Validations::Sales::FinancialValidations
end end
end end
def validate_percentage_bought_not_equal_percentage_owned(record)
return unless record.stairbought && record.stairowned
return unless record.saledate && record.form.start_year_after_2024?
if record.stairbought == record.stairowned
record.errors.add :stairbought, I18n.t("validations.financial.staircasing.percentage_bought_equal_percentage_owned", stairbought: sprintf("%g", record.stairbought), stairowned: sprintf("%g", record.stairowned))
record.errors.add :stairowned, I18n.t("validations.financial.staircasing.percentage_bought_equal_percentage_owned", stairbought: sprintf("%g", record.stairbought), stairowned: sprintf("%g", record.stairowned))
end
end
def validate_percentage_bought_at_least_threshold(record) def validate_percentage_bought_at_least_threshold(record)
return unless record.stairbought && record.type return unless record.stairbought && record.type

1
config/locales/en.yml

@ -427,6 +427,7 @@ en:
staircasing: staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction" percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction"
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%" percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%"
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
monthly_leasehold_charges: monthly_leasehold_charges:
not_zero: "Monthly leasehold charges cannot be £0 if the property has monthly charges" not_zero: "Monthly leasehold charges cannot be £0 if the property has monthly charges"
equity: equity:

47
spec/models/validations/sales/financial_validations_spec.rb

@ -156,6 +156,53 @@ RSpec.describe Validations::Sales::FinancialValidations do
end end
end end
describe "#validate_percentage_bought_not_equal_percentage_owned" do
let(:record) { FactoryBot.create(:sales_log) }
context "with 24/25 logs" do
before do
record.saledate = Time.zone.local(2024, 4, 3)
record.save!(validate: false)
end
it "does not add an error if the percentage bought is less than the percentage owned" do
record.stairbought = 20
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
it "adds an error if the percentage bought is equal to the percentage owned" do
record.stairbought = 30
record.stairowned = 30
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors["stairowned"]).to include("The percentage bought is 30% and the percentage owned in total is 30%. These figures cannot be the same.")
expect(record.errors["stairbought"]).to include("The percentage bought is 30% and the percentage owned in total is 30%. These figures cannot be the same.")
end
it "does not add an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do
record.stairbought = 50
record.stairowned = 40
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
end
context "with 23/24 logs" do
before do
record.saledate = Time.zone.local(2023, 4, 3)
record.save!(validate: false)
end
it "does not add an error if the percentage bought is equal to the percentage owned" do
record.stairbought = 30
record.stairowned = 30
financial_validator.validate_percentage_bought_not_equal_percentage_owned(record)
expect(record.errors).to be_empty
end
end
end
describe "#validate_monthly_leasehold_charges" do describe "#validate_monthly_leasehold_charges" do
let(:record) { FactoryBot.create(:sales_log) } let(:record) { FactoryBot.create(:sales_log) }

2
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -88,7 +88,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
field_85: "5", field_85: "5",
field_86: "1", field_86: "1",
field_87: "10", field_87: "10",
field_88: "10", field_88: "11",
field_89: "1", field_89: "1",
field_91: "30", field_91: "30",
field_92: "3", field_92: "3",

Loading…
Cancel
Save