diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 6ac2979c8..ad6984e07 100644 --- a/app/models/sales_log.rb +++ b/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 diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 3e1d3dfb8..9a119475f 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/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 diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index dd71d0b24..d9f47d39a 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/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