Browse Source

feat: update status before validation to prevent issue in future

pull/1931/head
natdeanlewissoftwire 3 years ago
parent
commit
24141331ba
  1. 14
      app/models/log.rb

14
app/models/log.rb

@ -8,7 +8,7 @@ class Log < ApplicationRecord
belongs_to :updated_by, class_name: "User", optional: true belongs_to :updated_by, class_name: "User", optional: true
belongs_to :bulk_upload, optional: true belongs_to :bulk_upload, optional: true
before_save :update_status! before_validation :update_status!
STATUS = { STATUS = {
"not_started" => 0, "not_started" => 0,
@ -188,6 +188,12 @@ class Log < ApplicationRecord
form.edit_end_date < Time.zone.now || older_than_previous_collection_year? form.edit_end_date < Time.zone.now || older_than_previous_collection_year?
end end
def update_status!
return if skip_update_status
self.status = calculate_status
end
private private
# Handle logs that are older than previous collection start date # Handle logs that are older than previous collection start date
@ -208,12 +214,6 @@ private
end end
end end
def update_status!
return if skip_update_status
self.status = calculate_status
end
def all_subsections_completed? def all_subsections_completed?
form.subsections.all? { |subsection| subsection.complete?(self) || subsection.not_displayed_in_tasklist?(self) } form.subsections.all? { |subsection| subsection.complete?(self) || subsection.not_displayed_in_tasklist?(self) }
end end

Loading…
Cancel
Save