Browse Source

Make proplen optional for 22/23 collection (#1361)

pull/1371/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
cb07cafe2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/lettings_log.rb
  2. 5
      app/models/log.rb
  3. 16
      app/models/sales_log.rb
  4. 24
      spec/models/sales_log_spec.rb

5
app/models/lettings_log.rb

@ -65,11 +65,6 @@ class LettingsLog < Log
FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form
end end
def recalculate_start_year!
@start_year = nil
collection_start_year
end
def lettings? def lettings?
true true
end end

5
app/models/log.rb

@ -39,6 +39,11 @@ class Log < ApplicationRecord
@start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year @start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year
end end
def recalculate_start_year!
@start_year = nil
collection_start_year
end
def lettings? def lettings?
false false
end end

16
app/models/sales_log.rb

@ -24,6 +24,7 @@ class SalesLog < Log
has_paper_trail has_paper_trail
validates_with SalesLogValidator validates_with SalesLogValidator
before_validation :recalculate_start_year!, if: :saledate_changed?
before_validation :reset_invalidated_dependent_fields! before_validation :reset_invalidated_dependent_fields!
before_validation :process_postcode_changes!, if: :postcode_full_changed? before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
@ -65,7 +66,20 @@ class SalesLog < Log
end end
def optional_fields def optional_fields
OPTIONAL_FIELDS OPTIONAL_FIELDS + dynamically_not_required
end
def dynamically_not_required
not_required = []
not_required << "proplen" if proplen_optional?
not_required
end
def proplen_optional?
return false unless collection_start_year
collection_start_year < 2023
end end
def not_started? def not_started?

24
spec/models/sales_log_spec.rb

@ -90,6 +90,30 @@ RSpec.describe SalesLog, type: :model do
expect(completed_sales_log.not_started?).to be(false) expect(completed_sales_log.not_started?).to be(false)
expect(completed_sales_log.completed?).to be(true) expect(completed_sales_log.completed?).to be(true)
end end
context "when proplen is not given" do
before do
Timecop.freeze(Time.zone.local(2023, 5, 1))
end
after do
Timecop.unfreeze
end
it "is set to completed for a log with a saledate before 23/24" do
completed_sales_log.update!(proplen: nil, saledate: Time.zone.local(2022, 5, 1))
expect(completed_sales_log.in_progress?).to be(false)
expect(completed_sales_log.not_started?).to be(false)
expect(completed_sales_log.completed?).to be(true)
end
it "is set to in_progress for a log with a saledate after 23/24" do
completed_sales_log.update!(proplen: nil, saledate: Time.zone.local(2023, 5, 1))
expect(completed_sales_log.in_progress?).to be(true)
expect(completed_sales_log.not_started?).to be(false)
expect(completed_sales_log.completed?).to be(false)
end
end
end end
context "when filtering by organisation" do context "when filtering by organisation" do

Loading…
Cancel
Save