Browse Source

compare correct charges

pull/1763/head
Kat 3 years ago
parent
commit
f92b0594f8
  1. 12
      app/controllers/duplicate_logs_controller.rb
  2. 5
      app/models/lettings_log.rb
  3. 18
      spec/models/lettings_log_spec.rb

12
app/controllers/duplicate_logs_controller.rb

@ -28,7 +28,17 @@ private
def duplicate_check_question_ids def duplicate_check_question_ids
if @log.lettings? if @log.lettings?
["owning_organisation_id", "startdate", "tenancycode", @log.is_general_needs? ? "postcode_full" : nil, @log.is_supported_housing? ? "location_id" : nil, "age1", "sex1", "ecstat1", "tcharge"].compact ["owning_organisation_id",
"startdate",
"tenancycode",
@log.is_general_needs? ? "postcode_full" : nil,
@log.is_supported_housing? ? "location_id" : nil,
"age1",
"sex1",
"ecstat1",
@log.household_charge == 1 ? "household_charge" : nil,
!@log.is_carehome? && @log.household_charge != 1 ? "tcharge" : nil,
@log.is_carehome? ? "chcharge" : nil].compact
else else
%w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full] %w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full]
end end

5
app/models/lettings_log.rb

@ -60,9 +60,10 @@ class LettingsLog < Log
.where.not(startdate: nil) .where.not(startdate: nil)
.where.not(sex1: nil) .where.not(sex1: nil)
.where.not(ecstat1: nil) .where.not(ecstat1: nil)
.where.not(tcharge: nil)
.where.not(needstype: nil) .where.not(needstype: nil)
.where("age1 IS NOT NULL OR age1_known = 1") .where("age1 IS NOT NULL OR age1_known = 1")
.where("tcharge IS NOT NULL OR household_charge = 1 OR is_carehome = 1")
.where("chcharge IS NOT NULL OR is_carehome IS NULL OR is_carehome = 0")
.where("location_id = ? OR needstype = 1", log.location_id) .where("location_id = ? OR needstype = 1", log.location_id)
.where("postcode_full = ? OR needstype = 2", log.postcode_full) .where("postcode_full = ? OR needstype = 2", log.postcode_full)
} }
@ -74,7 +75,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 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 SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1_known age1 sex1 ecstat1 tcharge].freeze DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze
def form def form
FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form

18
spec/models/lettings_log_spec.rb

@ -2920,6 +2920,24 @@ RSpec.describe LettingsLog do
duplicate_supported_housing_log.update!(location: location_2) duplicate_supported_housing_log.update!(location: location_2)
expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log) expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log)
end end
it "does not compare tcharge if there are no household charges" do
supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
duplicate_supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
expect(described_class.duplicate_logs(supported_housing_log)).to include(duplicate_supported_housing_log)
end
it "compares chcharge if it's a carehome" do
supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
expect(described_class.duplicate_logs(supported_housing_log)).to include(duplicate_supported_housing_log)
end
it "does not return a duplicate if carehome charge is not given" do
supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil)
expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log)
end
end end
end end
end end

Loading…
Cancel
Save