Browse Source

Trigger duplicate log check on buyer 1 age not known

pull/1763/head
Kat 3 years ago
parent
commit
15a9209cf6
  1. 12
      app/models/lettings_log.rb
  2. 8
      app/models/sales_log.rb
  3. 9
      spec/models/lettings_log_spec.rb
  4. 27
      spec/models/sales_log_spec.rb

12
app/models/lettings_log.rb

@ -54,9 +54,15 @@ class LettingsLog < Log
scope :unresolved, -> { where(unresolved: true) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :duplicate_logs, lambda { |log|
visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
visible
.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
.where.not(id: log.id)
.where.not("startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR needstype IS NULL")
.where.not(startdate: nil)
.where.not(sex1: nil)
.where.not(ecstat1: nil)
.where.not(tcharge: nil)
.where.not(needstype: nil)
.where("age1 IS NOT NULL OR age1_known = 1")
.where("location_id = ? OR needstype = 1", log.location_id)
.where("postcode_full = ? OR needstype = 2", log.postcode_full)
}
@ -68,7 +74,7 @@ class LettingsLog < Log
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1 sex1 ecstat1 tcharge].freeze
DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1_known age1 sex1 ecstat1 tcharge].freeze
def form
FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form

8
app/models/sales_log.rb

@ -44,12 +44,16 @@ class SalesLog < Log
scope :duplicate_logs, lambda { |log|
visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
.where.not(id: log.id)
.where.not("saledate is NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR postcode_full IS NULL")
.where.not(saledate: nil)
.where.not(sex1: nil)
.where.not(ecstat1: nil)
.where.not(postcode_full: nil)
.where("age1 IS NOT NULL OR age1_known = 1 OR age1_known = 2")
}
OPTIONAL_FIELDS = %w[purchid othtype].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[purchid saledate age1 sex1 ecstat1 postcode_full].freeze
DUPLICATE_LOG_ATTRIBUTES = %w[purchid saledate age1_known age1 sex1 ecstat1 postcode_full].freeze
def lettings?
false

9
spec/models/lettings_log_spec.rb

@ -2896,6 +2896,15 @@ RSpec.describe LettingsLog do
end
end
context "when there is a log with age1 not known" do
let!(:age1_not_known) { create(:lettings_log, :duplicate, age1_known: 1, age1: nil) }
it "returns the log as a duplicate if age1 is not known" do
log.update!(age1_known: 1, age1: nil)
expect(described_class.duplicate_logs(log)).to include(age1_not_known)
end
end
context "when there is a duplicate supported housing log" do
let(:scheme) { create(:scheme) }
let(:location) { create(:location, scheme:) }

27
spec/models/sales_log_spec.rb

@ -249,6 +249,33 @@ RSpec.describe SalesLog, type: :model do
expect(described_class.duplicate_logs(log)).to include(purchid_not_given)
end
end
context "when there is a log age not known" do
let!(:age1_not_known) { create(:sales_log, :duplicate, age1_known: 1, age1: nil) }
it "returns the log as a duplicate if age is not known" do
log.update!(age1_known: 1, age1: nil)
expect(described_class.duplicate_logs(log)).to include(age1_not_known)
end
end
context "when there is a log age pefers not to say" do
let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil) }
it "returns the log as a duplicate if age is prefers not to say" do
log.update!(age1_known: 2, age1: nil)
expect(described_class.duplicate_logs(log)).to include(age1_prefers_not_to_say)
end
end
context "when there is a log age pefers not to say and not known" do
let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil) }
it "does not return the log as a duplicate if age is prefers not to say" do
log.update!(age1_known: 1, age1: nil)
expect(described_class.duplicate_logs(log)).not_to include(age1_prefers_not_to_say)
end
end
end
describe "derived variables" do

Loading…
Cancel
Save