Browse Source

Update equity validation for resale (#2559)

pull/2587/head
kosiakkatrina 4 months ago committed by GitHub
parent
commit
eb355d6829
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/models/sales_log.rb
  2. 3
      app/models/validations/sales/financial_validations.rb
  3. 10
      spec/models/validations/sales/financial_validations_spec.rb

4
app/models/sales_log.rb

@ -542,4 +542,8 @@ class SalesLog < Log
def address_search_given?
address_line1_input.present? && postcode_full_input.present?
end
def is_resale?
resale == 1
end
end

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

@ -96,9 +96,10 @@ module Validations::Sales::FinancialValidations
if record.equity < range.min
record.errors.add :type, I18n.t("validations.financial.equity.under_min", min_equity: range.min)
record.errors.add :equity, :under_min, message: I18n.t("validations.financial.equity.under_min", min_equity: range.min)
elsif record.equity > range.max
elsif !record.is_resale? && record.equity > range.max
record.errors.add :type, I18n.t("validations.financial.equity.over_max", max_equity: range.max)
record.errors.add :equity, :over_max, message: I18n.t("validations.financial.equity.over_max", max_equity: range.max)
record.errors.add :resale, I18n.t("validations.financial.equity.over_max", max_equity: range.max)
end
end

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

@ -338,7 +338,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
describe "#validate_equity_in_range_for_year_and_type" do
let(:record) { FactoryBot.build(:sales_log, saledate:) }
let(:record) { FactoryBot.build(:sales_log, saledate:, resale: nil) }
context "with a log in the 22/23 collection year" do
let(:saledate) { Time.zone.local(2023, 1, 1) }
@ -373,6 +373,14 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.over_max", max_equity: 75))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.over_max", max_equity: 75))
end
it "does not add an error if it's a resale" do
record.type = 2
record.equity = 90
record.resale = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
end
context "with a log in 23/24 collection year" do

Loading…
Cancel
Save