Skip to content

Commit

Permalink
Merge pull request #2021 from unboxed/set-received-at-statically
Browse files Browse the repository at this point in the history
Explicitly set planning_application#received_at when creating application
  • Loading branch information
benjamineskola authored Nov 6, 2024
2 parents 92093de + d62d8af commit 254d32a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/planning_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class WithdrawOrCancelError < RuntimeError; end

before_validation :set_application_number, on: :create
before_validation :set_reference, on: :create
before_create :set_received_at
before_create :set_key_dates
before_create :set_change_access_id
before_create :update_lonlat
Expand Down Expand Up @@ -1001,6 +1002,10 @@ def set_reference
].join("-")
end

def set_received_at
self.received_at ||= Time.next_immediate_business_day(created_at || Time.current)
end

def set_key_dates
return if environment_impact_assessment_required? || time_extension_validation_requests.any?(:accepted)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class SetPlanningApplicationReceivedAtWhereNull < ActiveRecord::Migration[7.1]
def change
up_only do
PlanningApplication.find_each do |p|
p.update(received_at: p.received_at || Time.next_immediate_business_day(p.created_at))
end
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_10_23_140405) do
ActiveRecord::Schema[7.1].define(version: 2024_11_05_161333) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "plpgsql"
Expand Down

0 comments on commit 254d32a

Please sign in to comment.