Browse Source

Move redundant methods to log parent class

pull/863/head
Kat 3 years ago committed by baarkerlounger
parent
commit
f60df92949
  1. 21
      app/models/lettings_log.rb
  2. 23
      app/models/log.rb
  3. 23
      app/models/sales_log.rb

21
app/models/lettings_log.rb

@ -528,16 +528,6 @@ private
PIO = PostcodeService.new
def update_status!
self.status = if all_fields_completed? && errors.empty?
"completed"
elsif all_fields_nil?
"not_started"
else
"in_progress"
end
end
def reset_not_routed_questions
enabled_questions = form.enabled_page_questions(self)
enabled_question_ids = enabled_questions.map(&:id)
@ -689,17 +679,6 @@ private
end
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses == [:completed]
end
def all_fields_nil?
not_started_statuses = %i[not_started cannot_start_yet]
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses.all? { |status| not_started_statuses.include?(status) }
end
def age_refused?
[age1_known, age2_known, age3_known, age4_known, age5_known, age6_known, age7_known, age8_known].any?(1)
end

23
app/models/log.rb

@ -4,4 +4,27 @@ class Log < ApplicationRecord
belongs_to :owning_organisation, class_name: "Organisation", optional: true
belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true
private
def update_status!
self.status = if all_fields_completed? && errors.empty?
"completed"
elsif all_fields_nil?
"not_started"
else
"in_progress"
end
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses == [:completed]
end
def all_fields_nil?
not_started_statuses = %i[not_started cannot_start_yet]
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses.all? { |status| not_started_statuses.include?(status) }
end
end

23
app/models/sales_log.rb

@ -46,27 +46,4 @@ class SalesLog < Log
def completed?
status == "completed"
end
private
def update_status!
self.status = if all_fields_completed? && errors.empty?
"completed"
elsif all_fields_nil?
"not_started"
else
"in_progress"
end
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses == [:completed]
end
def all_fields_nil?
not_started_statuses = %i[not_started cannot_start_yet]
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses.all? { |status| not_started_statuses.include?(status) }
end
end

Loading…
Cancel
Save