Skip to content

Commit

Permalink
Merge branch 'qa'
Browse files Browse the repository at this point in the history
  • Loading branch information
smeeks committed Aug 20, 2023
2 parents 5adab30 + 69e9242 commit 6bcb07d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
23 changes: 23 additions & 0 deletions app/jobs/close_scenarios_on_rollover_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#------------------------------------------------------------------------------
#
# CloseScenariosOnRolloverJob
#
# Build SOGR projects
#
#------------------------------------------------------------------------------
class CloseScenariosOnRolloverJob < Job

def run
scenarios = Scenario.where.not(state: ['approved', 'cancelled'])
@logger.info "Closing #{scenarios.count} scenarios"
scenarios.each do |s|
# Possible race condition here
s.cancel unless s.state == 'approved'
end
end

def prepare
@logger = Delayed::Worker.logger || Rails.logger
@logger.info "Executing CloseScenariosOnRolloverJob at #{Time.now.to_s}"
end
end
10 changes: 6 additions & 4 deletions app/models/replacement_status_update_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def api_json(options={})
protected

def update_asset
Rails.logger.debug "Updating replacement status for asset = #{transam_asset.object_key}"

Rails.logger.debug "Updating replacement status for asset = #{transam_asset.object_key} to #{replacement_status_type_id}"
transam_asset.reload
if transam_asset.replacement_status_updates.empty?
transam_asset.replacement_status_type = nil
else
Expand All @@ -87,8 +87,10 @@ def update_asset
transam_asset.save(validate: false)

# update asset and cost(s) in project planner
service = CapitalProjectBuilder.new
service.update_asset_schedule(transam_asset)
if transam_asset.replacement_by_policy?
service = CapitalProjectBuilder.new
service.update_asset_schedule(transam_asset)
end
end

# Set resonable defaults for a new condition update event
Expand Down
25 changes: 24 additions & 1 deletion app/models/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Scenario < ApplicationRecord
:unconstrained_plan,
:submitted_unconstrained_plan,
:constrained_plan,
:submitted_constrained_plan
:submitted_constrained_plan,
:final_draft,
:awaiting_final_approval
]

# STATE WHERE WE ARE DEALING WITH BUDGETS
Expand Down Expand Up @@ -291,6 +293,12 @@ def in_chart_state?
transition :cancelled => :unconstrained_plan
end

#---------------------------------------------------------------------------
# Transition actions
#---------------------------------------------------------------------------

after_transition :mark_assets_underway, all => :approved

end

#---------------------------------------------------------------------------
Expand All @@ -302,6 +310,10 @@ def dotgrants_json
#Add on the ALIs
export[:activity_line_items] = draft_project_phases.where(fy_year: fy_year).map{ |ali| ali.dotgrants_json}
export[:funding_templates] = FundingTemplate.all.map{ |funding_template| funding_template.as_json }
if organization.organization_type == OrganizationType.find_by(class_name: "TransitOperator")
export[:email] = organization.executive_director&.email
end
export[:fein] = organization.subrecipient_number
return export
end

Expand All @@ -324,6 +336,17 @@ def state_owner
end
end

def mark_assets_underway
underway_id = ReplacementStatusType.where(name: 'Underway').pluck(:id).first
comment = "The #{name} plan includes the replacement of this asset."
draft_project_phases.where(fy_year: fy_year).each do |dpp|
dpp.transit_assets.each do |ta|
ReplacementStatusUpdateEvent.create(transam_asset: ta.transam_asset, replacement_year: fy_year,
replacement_status_type_id: underway_id, comments: comment)
end
end
end

#---------------------------------------------------------------------------
# State Machine Validations
#---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/transam_cpt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamCpt
VERSION = "2.30.0"
VERSION = "2.33.0"
end

0 comments on commit 6bcb07d

Please sign in to comment.