Browse Source

Extract duplicate log fields as contsants

pull/1762/head
Kat 3 years ago
parent
commit
807e14884f
  1. 8
      app/models/lettings_log.rb
  2. 4
      app/models/sales_log.rb

8
app/models/lettings_log.rb

@ -54,8 +54,7 @@ class LettingsLog < Log
scope :unresolved, -> { where(unresolved: true) } scope :unresolved, -> { where(unresolved: true) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :duplicate_logs, lambda { |log| scope :duplicate_logs, lambda { |log|
attrs_to_check = %w[tenancycode propcode startdate age1 sex1 ecstat1 tcharge postcode_full] where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
where(log.slice(*attrs_to_check))
.where.not(id: log.id) .where.not(id: log.id)
.where.not(status: "deleted") .where.not(status: "deleted")
.where.not("startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR postcode_full IS NULL OR propcode IS NULL OR needstype IS NULL") .where.not("startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR postcode_full IS NULL OR propcode IS NULL OR needstype IS NULL")
@ -70,6 +69,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 propcode startdate age1 sex1 ecstat1 tcharge postcode_full].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
@ -531,6 +531,10 @@ class LettingsLog < Log
end end
end end
def duplicate_log_attributes
%w[tenancycode propcode startdate age1 sex1 ecstat1 tcharge postcode_full]
end
private private
def reset_invalid_unresolved_log_fields! def reset_invalid_unresolved_log_fields!

4
app/models/sales_log.rb

@ -42,8 +42,7 @@ class SalesLog < Log
} }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
scope :duplicate_logs, lambda { |log| scope :duplicate_logs, lambda { |log|
attrs_to_check = %w[purchid saledate age1 sex1 ecstat1 postcode_full] where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
where(log.slice(*attrs_to_check))
.where.not(id: log.id) .where.not(id: log.id)
.where.not(status: "deleted") .where.not(status: "deleted")
.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 is NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR postcode_full IS NULL")
@ -52,6 +51,7 @@ class SalesLog < Log
OPTIONAL_FIELDS = %w[purchid othtype].freeze OPTIONAL_FIELDS = %w[purchid othtype].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
DUPLICATE_LOG_ATTRIBUTES = %w[purchid saledate age1 sex1 ecstat1 postcode_full].freeze
def lettings? def lettings?
false false

Loading…
Cancel
Save