Browse Source

feat: enforce saledate not after 22/23 collection year end

pull/1232/head
natdeanlewissoftwire 3 years ago
parent
commit
dd408194f7
  1. 2
      app/models/validations/sales/sale_information_validations.rb
  2. 2
      app/models/validations/sales/setup_validations.rb
  3. 14
      db/schema.rb
  4. 12
      spec/models/validations/sales/setup_validations_spec.rb

2
app/models/validations/sales/sale_information_validations.rb

@ -15,7 +15,7 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :saledate, I18n.t("validations.sale_information.saledate.must_be_after_exdate")
end
if record.saledate - record.exdate > 1.year
if record.saledate - record.exdate >= 1.year
record.errors.add :exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate")
record.errors.add :saledate, I18n.t("validations.sale_information.saledate.must_be_less_than_1_year_from_exdate")
end

2
app/models/validations/sales/setup_validations.rb

@ -2,7 +2,7 @@ module Validations::Sales::SetupValidations
def validate_saledate(record)
return unless record.saledate
if record.saledate < Time.zone.local(2022, 4, 1)
unless Time.zone.local(2022, 4, 1) <= record.saledate && record.saledate < Time.zone.local(2023, 4, 1)
record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year")
end
end

14
db/schema.rb

@ -490,20 +490,20 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_151942) do
t.integer "mortgagelender"
t.string "mortgagelenderother"
t.integer "mortlen"
t.string "pcode1"
t.string "pcode2"
t.integer "pcodenk"
t.string "postcode_full"
t.boolean "is_la_inferred"
t.integer "extrabor"
t.integer "hhmemb"
t.integer "totadult"
t.integer "totchild"
t.integer "hhtype"
t.integer "hodate_check"
t.string "pcode1"
t.string "pcode2"
t.integer "pcodenk"
t.string "postcode_full"
t.boolean "is_la_inferred"
t.bigint "bulk_upload_id"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.integer "retirement_value_check"
t.integer "hodate_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

12
spec/models/validations/sales/setup_validations_spec.rb

@ -26,7 +26,7 @@ RSpec.describe Validations::Sales::SetupValidations do
end
end
context "when saledate is not the 22/23 financial year" do
context "when saledate is before the 22/23 financial year" do
let(:record) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2022, 1, 1)) }
it "adds error" do
@ -35,5 +35,15 @@ RSpec.describe Validations::Sales::SetupValidations do
expect(record.errors[:saledate]).to include(I18n.t("validations.setup.saledate.financial_year"))
end
end
context "when saledate is after the 22/23 financial year" do
let(:record) { FactoryBot.build(:sales_log, saledate: Time.zone.local(2023, 4, 1)) }
it "adds error" do
setup_validator.validate_saledate(record)
expect(record.errors[:saledate]).to include(I18n.t("validations.setup.saledate.financial_year"))
end
end
end
end

Loading…
Cancel
Save