diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 1b32e544f..18900bcd9 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -98,11 +98,12 @@ class LettingsLog < Log } scope :location_answered, -> { where.not(location_id: nil).or(where(needstype: 1)).or(filter_by_year_or_later(2026)) } scope :postcode_answered, -> { where.not(postcode_full: nil).or(where(needstype: 2)) } + scope :sex1_answered, -> { where.not(sex1: nil).filter_by_year_or_earlier(2025).or(where.not(sexrab1: nil).filter_by_year_or_later(2026)) } scope :duplicate_logs, lambda { |log| visible .where.not(id: log.id) .where.not(startdate: nil) - .where.not(sex1: nil) + .sex1_answered .where.not(ecstat1: nil) .where.not(needstype: nil) .age1_answered @@ -142,7 +143,7 @@ class LettingsLog < Log # separate function as location needs to be fully ignored in 2026 .group(*DUPLICATE_LOG_ATTRIBUTES, :postcode_full, :uprn, :address_line1) .where.not(startdate: nil) - .where.not(sex1: nil) + .where.not(sexrab1: nil) .where.not(ecstat1: nil) .where.not(needstype: nil) .age1_answered diff --git a/lib/tasks/handle_unpended_logs.rake b/lib/tasks/handle_unpended_logs.rake index 7e2c07862..8c023caaf 100644 --- a/lib/tasks/handle_unpended_logs.rake +++ b/lib/tasks/handle_unpended_logs.rake @@ -41,7 +41,7 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, args| # This is the normal query for duplicates but without the check that the logs are visible (i.e. not deleted/pending) duplicates = LettingsLog.where.not(id: log.id) .where.not(startdate: nil) - .where.not(sex1: nil) + .sex1_answered .where.not(ecstat1: nil) .where.not(needstype: nil) .age1_answered