From f92b0594f87520185a35c894e8fe1b61b8ce9506 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 10 Jul 2023 15:41:09 +0100 Subject: [PATCH] compare correct charges --- app/controllers/duplicate_logs_controller.rb | 12 +++++++++++- app/models/lettings_log.rb | 5 +++-- spec/models/lettings_log_spec.rb | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/controllers/duplicate_logs_controller.rb b/app/controllers/duplicate_logs_controller.rb index 9539494c0..42a4e561d 100644 --- a/app/controllers/duplicate_logs_controller.rb +++ b/app/controllers/duplicate_logs_controller.rb @@ -28,7 +28,17 @@ private def duplicate_check_question_ids 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 %w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full] end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index e6df9e54a..a1094ee37 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -60,9 +60,10 @@ class LettingsLog < Log .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("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("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 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_known age1 sex1 ecstat1 tcharge].freeze + DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze def form FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index edc50bb10..e2a15874a 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2920,6 +2920,24 @@ RSpec.describe LettingsLog do duplicate_supported_housing_log.update!(location: location_2) expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log) 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